Darshana
Darshana

Reputation: 2548

link_to gives an error

In my index.html.erb

<p><%= link_to "log Out", :action => 'logout' %></p>

In home controller.rb

def logout
end

and gives me error

Routing Error

No route matches {:action=>"logout", :controller=>"home"}

this maybe simple question. I'm new to rails.

Upvotes: 0

Views: 82

Answers (2)

Prathamesh Sonpatki
Prathamesh Sonpatki

Reputation: 906

Please check if the route exists in routes.rb I seems that you have added the action in controller but not added the route in routes.rb An alternative to manually adding routes to routes.rb, you can run a command like this

rails g controller home log_out

Then keep the home_controller.rb file as it was.(Don't overwrite it). This command will add a route automatically in routes.rb

Upvotes: 3

RAJ
RAJ

Reputation: 9747

You have to specify route for 'logout' method in routes.rb

you can do it like this:

resource :home do
  collection do
   get 'logout'
  end
end

OR

you need to just add

  get 'home/logout'

Upvotes: 1

Related Questions