开发者

passing a parameter to the link_to method

开发者 https://www.devze.com 2023-02-19 19:06 出处:网络
How do you pass a parameter through the MVC using the link_to method? view: <%= link_to \"Remove Tag\", remove_tag_issue_path(issue)%&开发者_运维问答gt;

How do you pass a parameter through the MVC using the link_to method?

view:

<%= link_to "Remove Tag", remove_tag_issue_path(issue)%&开发者_运维问答gt;

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

issues_controller.rb

  def remove_tag(parameter)
     @issue.remove_it(parameter)
  end

issue.rb

  def remove_it(parameter)
      self.users.delete(User.find(parameter))
   end


In controller

def remove_tag
  @issue.remove_it(params[:my_param])
end

And in view

<%= link_to "Remove Tag", remove_tag_issue_path(issue, :my_param => "Hello world")%>


In the view use the following

<%= link_to 'Remove Tag', remove_tag_issue_path(:issue => @issue)%>

and in controller

def remove_tag
  @issue.remove_it(:issue => params[:issue])
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号