2011-03-26 7 views
0

link_to 메서드를 사용하여 remove_tag 동작을 어떻게 활용합니까?Ruby on rails link_to 구문

issues_controller.rb 그것은 당신이 당신의 경로를 설정 한 방법에 따라 달라집니다

def remove_tag 
    @issue.remove_it 
    end 

issue.rb

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

답변

2
<%= link_to "Remove Tag", remove_tag_issue_path(@issue) %> 

또는

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

그리고 remove_tag 조치를 라우팅에 정의 된대로 사용 member fo r 발행 자원

+0

+1. 나는 이것이 [polymorphic_url] (http://apidock.com/rails/ActionController/PolymorphicRoutes/polymorphic_url)의 지름길임을 이해하면서 두 번째 옵션 –

+0

을 알지 못했습니다. – fl00r

1

. 표준 자원 라우트가 아니므로 해당 조치에 대해 이름 지정된 라우트를 사용해야 할 수도 있습니다.

나는 당신이이 글을 읽을 제안 :

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

lint_to이 같은 경로에 제시해야한다