For each project that a user has blueprints for, I want to show the projects name and link to the project_path. Thanks.
These are my ActiveRecords
class User < ActiveRecord::Base
attr_accessible :id, :name
has_many :blueprints
has_many :projects, :through => :blueprints
end
class Project < ActiveRecord::Base
attr_accessible :id, :name
has_many :blueprints
has_many :users, :through => :blueprints
end
class Blueprint < ActiveRecord::Base
attr_accessible :id, :name, :project_id, :user_id
belongs_to :user
belongs_to :project
end
My Users show Controller
def show
@user = User.find(params[:id])
@project = Project.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @user }
end
end
My Views/Users/Show.html.erb Table
<table>
<tr>
<% @projects.each do |p| %>
<td><%= p.name %></td>
<% end %>
</tr>
</table>
For these requirements, you can remove the
@projectassignment from your action. You need to look at theblueprintsrelation for@user, and get the associatedprojectfor each of thoseblueprints.