简体   繁体   English

使用Ruby on Rails进行按钮重定向

[英]Button redirection using Ruby on Rails

I'm just starting out with ruby on rails and web applications. 我只是从在Rails和Web应用程序上使用ruby开始。 I just finished implementing a database with ruby. 我刚刚用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 http://mauricegs.imgur.com/buttons

You press the button that says "Productos" and it should send you to the "Productos" view. 您按下显示“ Productos”的按钮,它将使您进入“ Productos”视图。 I'm not sure what I should add at reference for productos Thanks 我不确定我应该在参考中添加哪些内容,谢谢

假设您在ProductosController上执行了index操作,并且有一个视图的路由:

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

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

Write rails link 写rails链接

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

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. ... Rails为您提供了一个辅助方法productos_path ,该方法将评估该路由的URL。 You can then use than in a button as RobM showed. 然后,您可以在RobM所示的按钮中使用than。

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. 如果productos是一种资源(意味着您的路由文件中有resources :productos ),那么上述路由将被自动添加,并且您仍将具有productos_path帮助器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM