Forum: Ruby on Rails find(params[:id]) question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rob B. (Guest)
on 2006-04-11 13:44
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?
Mikkel B. (Guest)
on 2006-04-11 13:59
(Received via mailing list)
def show
  @wizard = Wizard.find_by_user_name(params[:id])
end

On Tuesday, April 11, 2006, at 11:44 AM, Rob B. wrote:
>
>
>Any ideas?
>
>--
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>removed_email_address@domain.invalid
>http://lists.rubyonrails.org/mailman/listinfo/rails


Mikkel B.

www.strongside.dk    - Football Portal(DK)
ting.minline.dk      - Buy Old Stuff!(DK)
Rob B. (Guest)
on 2006-04-11 14:08
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 B. wrote:
> def show
>   @wizard = Wizard.find_by_user_name(params[:id])
> end
>
> On Tuesday, April 11, 2006, at 11:44 AM, Rob B. wrote:
>>
>>
>>Any ideas?
>>
>>--
>>Posted via http://www.ruby-forum.com/.
>>_______________________________________________
>>Rails mailing list
>>removed_email_address@domain.invalid
>>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
> Mikkel B.
>
> www.strongside.dk    - Football Portal(DK)
> ting.minline.dk      - Buy Old Stuff!(DK)
Tom M. (Guest)
on 2006-04-11 21:10
(Received via mailing list)
You need to remove the single quotes in the URL.

--
-- Tom M.
Matthijs L. (Guest)
on 2006-04-11 22:11
(Received via mailing list)
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.
This topic is locked and can not be replied to.