Search code examples
ruby-on-railsruby-on-rails-4ruby-on-rails-3.2rails-migrations

link_to with controller_name and action name not working


I'm working on upgrading rails 3.2 app to rails 4.2. I have stuck with one issue. link_to with controller and action name not working

<%= link_to "Login", :controller => "user", :action => "login" %>

This is the link I want to convert into rails 4 code. using the same fashion.

I have tried this way.

<%= link_to "Login", { controller: "user", action: "login" } %>

its gives be below error:

ArgumentError: wrong number of arguments (given 2, expected 0..1)

Is anyone faced this issue. I have google this but not solved this.


Solution

  • I was looking at the documentation https://apidock.com/rails/v4.0.2/ActionView/Helpers/UrlHelper/link_to

    <%= link_to "Profile", controller: "profiles", action: "show", id: @profile %>
    # => <a href="/profiles/show/1">Profile</a>
    

    you should be able to do

    <%= link_to "Login",  controller: "user", action: "login" %>