Find(params[:id]) question

Admin Controller -

def show
@wizard = Wizard.find(params[:id])
end

View -

<%= link_to 'Show', :action => 'show', :id => wizard %>

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?

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
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Mikkel B.

www.strongside.dk - Football Portal(DK)
ting.minline.dk - Buy Old Stuff!(DK)

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
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Mikkel B.

www.strongside.dk - Football Portal(DK)
ting.minline.dk - Buy Old Stuff!(DK)

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.

You need to remove the single quotes in the URL.


– Tom M.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs