Mauricio Garcia Sainz
Mauricio Garcia Sainz

Reputation: 21

Button redirection using Ruby on Rails

I'm just starting out with ruby on rails and web applications. I just finished implementing a database with ruby. I'm having trouble making my buttons in the homepage redirect to the views I'd like them to go to. I'm sure it's something very simple but I haven't been able to find a way to do it.

Here is a link to the idea. http://mauricegs.imgur.com/buttons

You press the button that says "Productos" and it should send you to the "Productos" view. I'm not sure what I should add at reference for productos Thanks

Upvotes: 1

Views: 12177

Answers (3)

Aleksandr Larionov
Aleksandr Larionov

Reputation: 126

Instead of <a href='#productos'>PRODUCTOS</a>

Write rails link

<%= link_to 'PRODUCTOS', productos_path, class: 'button alt' %>

Upvotes: 2

dvn928361
dvn928361

Reputation: 455

For a route declared like this...

get '/productos', to: 'productos#index', as: 'productos'

...Rails gives you a helper method productos_path which evaluates to the the URL of that route. You can then use than in a button as RobM showed.

If productos is a resource (meaning you have resources :productos in your routes file), the above route will have been automatically added and you'll still have the productos_path helper.

Upvotes: 0

Rob Mulholand
Rob Mulholand

Reputation: 899

Assuming you have an index action on your ProductosController and a route to the view:

<%= button_to "Productos", productos_path, method: :get %>

Upvotes: 6

Related Questions