link_to action e id

0

I want to make an action to change the password and I have the following link_to to redirect to html.erb with the correct user

<%= link_to 'Mudar Senha', "edit_password_form/" + @usuario.id.to_s %>

I feel like I'm doing the wrong thing, what's the best way to do it?

    
asked by anonymous 23.05.2014 / 01:39

1 answer

1

Check your routes of your project, giving the command rake routes from console , this command will return a list with 4 columns.

  • The 4 column is the action of your controller that should be executed (ex: show).
  • A 3 is the route as it is displayed in the address bar.
  • A 2 is the shipping method used by the action.
  • A 1 is the shortcut to use redirect.

Find the action you want to use in your controller in the 4 column and put in place of "edit_password_form /" + @ usuario.id.to_s what appears in the first column + path, if you need to specify an object pass it in the function ( ex edit_password_path(@usuario) ).

If the first column is empty you should look at its method, it will be the same as the top row, but you will need to specify the method with the method attribute (ex: method: :put )

Otherwise, you should add the route in your routes.rb (study on)

    
23.05.2014 / 19:57