On Feb 14, 3:32 am, Ken Lim <[email protected]> wrote:
> MaD wrote:
> > well, the error-message is pretty clear:
> >> The error occurred while evaluating nil.user
> >> 2: <%= link_to "#[email protected]}'s Photos",
>
> > @photo seems to be nil. the reason for it can be found in your
> > controller (where show is defined).
>
> I still have no clue at all as I follow the code from the book. The
> application trace state that the "respond to do |format|" in the show
> method has something wrong.
>
> Below is controller where show is defined:
>
Not necessarily. For example if the link you generated was not quite
right so that params[:user_id] or params[:id] were not correct then
Photo.find_by_user_id_and_id might quite legitimately return nil.
Fred
> Class UserPhotosController < ApplicationController
> before_filter :login_required, :except => [:index, :show]
>
> def index
> @user = User.find(params[:user_id])
> @photo_pages = Paginator.new(self, @user.photos.count, 9,
> params[:page])
> @photos = @user.photos.find(:all, :order => 'created_at DESC',
> :limit =>
> @photo_pages.items_per_page,
> :offset =>
> @photo_pages.current.offset)
> respond_to do |format|
> format.html # index.rhtml
> format.xml { render :xml => @photos.to_xml }
> end
> end
>
> def show
> @photo = Photo.find_by_user_id_and_id(params[:user_id],
> params[:id],
> :include => :user)
>
> respond_to do |format|
> format.html # show.rhtml
> format.xml { render :xml => @photo.to_xml }
> end
> end
> .
> .
> .
>
> Attachments:http://www.ruby-forum.com/attachment/3296/user_photos_controller.rb
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---