elhostis
elhostis

Reputation: 1087

link_to => undefined method path

I have created an object Events and I have refactored the controller. Now I have that :

The view :

<td><%= link_to 'Show', event %></td>

The route :

scope 'admin', :module => 'back', :as => 'back' do
  root :to => 'events#index'
  resources :events
end

The controller :

class Back::EventsController < BackController

But I have an error undefined method event_path. So I have changed the link with :

<td><%= link_to 'Show', back_event %></td>

because when I make a rake routes I see that :

          back_event GET    /admin/events/:id(.:format)      back/events#show
                     PATCH  /admin/events/:id(.:format)      back/events#update
                     PUT    /admin/events/:id(.:format)      back/events#update
                     DELETE /admin/events/:id(.:format)      back/events#destroy

But now, I have the error : undefined local variable or method `back_event

How can I create this link ?

Thanks.

Eric

Upvotes: 3

Views: 3635

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

<td><%= link_to 'Show', back_event_path(event) %></td>

You really need to spend some time reading the basics: http://guides.rubyonrails.org/routing.html

Upvotes: 2

Related Questions