位于app/controllers/forum_threads/forum_posts_controller.rb中的forum_posts控制器
我不知道是否必须在link_to中调用forum_threads:forum_posts。
控制器:
http://pastebin.com/t9vuyxdP
HTML:http://pastebin.com/LextuZ74
顺便说一句,如何向link_to添加按钮?我尝试在末尾添加:class => " button“,不会导致错误,但仍然只显示一个链接而不是一个按钮。
发布于 2015-11-18 01:45:52
如果您想将link_to与较旧样式的控制器/操作/id参数一起使用:
<%= link_to "Edit", :controller => "forum_threads/forum_posts", :action => "edit", :id => forum_post.id, :forum_thread_id => @forum_thread.id %>但只要有可能,Rails就更喜欢更新的RESTful路由。如果您在routes.rb中正确定义了控制器,则可以像这样编写link_to:
<%= link_to "Edit", edit_forum_thread_forum_post_path(@forum_thread, forum_post) %>2015年11月18日更新:您忘记在forum_thread_id link_to 中包含forum_thread_id,因为我看到您的路由需要 forum_thread_id 和参数才能运行。
有关
link_to的更多信息,请参阅:http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to
https://stackoverflow.com/questions/33762914
复制相似问题