Admin Controller - def show @wizard = Wizard.find(params[:id]) end View - <td><%= link_to ''Show'', :action => ''show'', :id => wizard %></td> URL - http://localhost:3000/admin/show/1 I want user_name (one of the columns in the database) instead of the id to show For example: http://localhost:3000/admin/show/''user_name'' Any ideas? -- Posted via http://www.ruby-forum.com/.
def show @wizard = Wizard.find_by_user_name(params[:id]) end On Tuesday, April 11, 2006, at 11:44 AM, Rob Balfour wrote:>Admin Controller - > >def show > @wizard = Wizard.find(params[:id]) >end > > >View - > ><td><%= link_to ''Show'', :action => ''show'', :id => wizard %></td> > > >URL - > >http://localhost:3000/admin/show/1 > > >I want user_name (one of the columns in the database) instead of the id >to show >For example: >http://localhost:3000/admin/show/''user_name'' > >Any ideas? > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsMikkel Bruun www.strongside.dk - Football Portal(DK) ting.minline.dk - Buy Old Stuff!(DK) -- Posted with http://DevLists.com. Sign up and save your mailbox.
That brings back: NoMethodError in Admin#show Showing app/views/admin/show.rhtml where line #1 raised: You have a nil object when you didn''t expect it! The error occured while evaluating nil.user_name Mikkel Bruun wrote:> def show > @wizard = Wizard.find_by_user_name(params[:id]) > end > > On Tuesday, April 11, 2006, at 11:44 AM, Rob Balfour wrote: >> >> >>Any ideas? >> >>-- >>Posted via http://www.ruby-forum.com/. >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails > > > Mikkel Bruun > > www.strongside.dk - Football Portal(DK) > ting.minline.dk - Buy Old Stuff!(DK)-- Posted via http://www.ruby-forum.com/.
You need to remove the single quotes in the URL. -- -- Tom Mornini On Apr 11, 2006, at 3:08 AM, Rob Balfour wrote:> That brings back: > > NoMethodError in Admin#show > > Showing app/views/admin/show.rhtml where line #1 raised: > > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.user_name > > > Mikkel Bruun wrote: >> def show >> @wizard = Wizard.find_by_user_name(params[:id]) >> end >> >> On Tuesday, April 11, 2006, at 11:44 AM, Rob Balfour wrote: >>> >>> >>> Any ideas? >>> >>> -- >>> Posted via http://www.ruby-forum.com/. >>> _______________________________________________ >>> Rails mailing list >>> Rails@lists.rubyonrails.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> Mikkel Bruun >> >> www.strongside.dk - Football Portal(DK) >> ting.minline.dk - Buy Old Stuff!(DK) > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Maybe it''s more sane to use params[:username] since whe are dealing with a username? Don''t get scared by the ugly admin/show/?username=john URL, just edit config/routes.rb to handle the URL mapping stuff. On 4/11/06, Tom Mornini <tmornini@infomania.com> wrote:> > You need to remove the single quotes in the URL. > > -- > -- Tom Mornini > > > On Apr 11, 2006, at 3:08 AM, Rob Balfour wrote: > > > That brings back: > > > > NoMethodError in Admin#show > > > > Showing app/views/admin/show.rhtml where line #1 raised: > > > > You have a nil object when you didn''t expect it! > > The error occured while evaluating nil.user_name > > > > > > Mikkel Bruun wrote: > >> def show > >> @wizard = Wizard.find_by_user_name(params[:id]) > >> end > >> > >> On Tuesday, April 11, 2006, at 11:44 AM, Rob Balfour wrote: > >>> > >>> > >>> Any ideas? > >>> > >>> -- > >>> Posted via http://www.ruby-forum.com/. > >>> _______________________________________________ > >>> Rails mailing list > >>> Rails@lists.rubyonrails.org > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> Mikkel Bruun > >> > >> www.strongside.dk - Football Portal(DK) > >> ting.minline.dk - Buy Old Stuff!(DK) > > > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060411/1e37e60a/attachment-0001.html