简体   繁体   English

Ruby on Rails链接语法

[英]Ruby on rails link_to syntax

How do I use the link_to method, to utilize the remove_tag action? 如何使用link_to方法来利用remove_tag操作?

issues_controller.rb issues_controller.rb

  def remove_tag
     @issue.remove_it
  end

issue.rb issue.rb

  def remove_it
      self.users.delete(User.find(1))
   end
<%= link_to "Remove Tag", remove_tag_issue_path(@issue) %>

or 要么

<%= link_to "Remove Tag", [:remove_tag, @issue] %>

And remove_tag action should be presented in routes as member for issue resources 并且remove_tag操作应作为问题资源的member在路由中显示

It depends on how you have set your routes. 这取决于您如何设置路线。 You might need to use a named route for that action as it is not a standard resource route. 您可能需要对该操作使用命名路由,因为它不是标准资源路由。

I suggest you read this: 我建议您阅读以下内容:

http://guides.rubyonrails.org/routing.html http://guides.rubyonrails.org/routing.html

lint_to uses whatever is defined in routing lint_to使用路由中定义的任何内容

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

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