我在下面提供了我的活动记录。在view/users/show中,我想通过蓝图显示用户正在处理的任何项目。当用户将多个蓝图添加到项目中时,项目会多次显示。我尝试了一些validate_uniqueness选项无济于事。显示多个相同记录的导轨
class Blueprint < ActiveRecord::Base
attr_accessible :id, :name, :project_id, :user_id, :loc
belongs_to :user
belongs_to :project
has_many :comments
end
class Project < ActiveRecord::Base
attr_accessible :id, :name
has_many :blueprints
has_many :users, :through => :blueprints
has_many :comments
end
class User < ActiveRecord::Base
attr_accessible :id, :name
has_many :blueprints
has_many :projects, :through => :blueprints
end
这里是显示同一项目的多个值的视图代码。
<% @user.blueprints.each do |blueprint| %>
<tr>
<td><%= link_to blueprint.project.name, project_path(blueprint.project) %></td>
</tr>
<% end %>
谢谢!
这没有奏效。我现在正在探索选项。 –
如果有帮助,我从视图中添加了我的代码。 –
感谢您的帮助。当进一步移动时,我去解决另一端的相同问题,并意识到当我添加cgat的解决方案时,我意外地留下了修复程序。你们俩都帮助我的小白! –