简体   繁体   中英

Ruby on rails link_to syntax

How do I use the link_to method, to utilize the remove_tag action?

issues_controller.rb

  def remove_tag
     @issue.remove_it
  end

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

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

lint_to uses whatever is defined in routing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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