-1
class ProfileController < ApplicationController

def show
    @user = current_user
    @first_name = @user.first_name
    @last_name = @user.last_name
end

def settings
end

def pics
    @photos = current_user.photos.all
end


end

in the view of _pics.html.erb, I have

<% @photos.each do |p| %>
<%= image_tag p.image(:medium) %>
<% end %>

If I change it to current_user.photos.each do |p|, it works, which is weird. I don't get an error from this code on my other computer.

4

1 回答 1

1

In a comment you said, that you render the pics partial from your show view. Since the show view is rendered by the show action and the show action does not set the @photos variable, you can't use that variable. So to fix your problem, you'd need to set the variable in the show action.

You seem to think that rendering the pics partial will invoke the pics action, but that's not the case. An action will only be invoked if an URL is accessed that's mapped to that using the routing system. Rendering partials does not invoke any actions.

Also it should just be @photos = current_user.photos without the all.

于 2013-05-25T23:55:01.420 回答