Search code examples
ruby-on-railslink-to

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.


Solution

  • 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