Simpleton
Simpleton

Reputation: 6415

Simple rails named routing issue

I'm stuck with this simple named route problem. I have:

#Controller:

  def show
    @thing = Thing.find(params[:id])
  end

#Routes.rb:

  match '/:name' => 'things#show'

The response I get is Couldn't find Thing without an ID. If I change the controller to:

@thing = Thing.find(params[:name])

Then I get Couldn't find Thing with ID=thing. What am I missing?

Upvotes: 1

Views: 52

Answers (1)

davidb
davidb

Reputation: 8954

@thing = Thing.find_by_name(params[:name])

Upvotes: 5

Related Questions