put show action on a profile page
class ProfileController < ApplicationController
def show
username = params[:username]
@user = User.find_by_username(username)
if @user
@title = "Profile for #{username}"
user_id = @user.id
@albums = Album.find(:all, :conditions => ["user_id = ?", user_id])
end
end
end
I have managed to display the index of albums for a given user on their profile page. Moving to the show action for an album di开发者_运维百科splays the pictures in the given album. How can I put the show action of the album on the user's profile page?
Assume that you set up a partial for showing a single album.
app/views/albums/_display.html.erb
<h2><%= h album.name %></h2>
<p><%= h album.description %></p>
On the user page, you could display the albums by rendering that partial.
<% @albums.each do |album| -%>
<%= render :partial => "/albums/display", :locals => {:album => album} %>
<% end -%>
精彩评论