2011-01-17 3 views
1

다음과 같이 간단한 렌더링이 있습니다.Rails 3 : RESTful 아키텍처에 따라 '삭제'로 작동하도록 form_for를 가져올 수 없음 => 항상 루팅 오류 발생

<%= form_for(:relationships, :url => relationships_path, :html => {:method => 'delete'}) do |f| %> 
<div><%= f.hidden_field :user_id_to_unfollow, :value => @user.id %></div> 
<div class="actions"><%= f.submit "Unfollow" %></div> 
<% end %> 

이 양식을 제출하면 항상 내 페이지에

Routing Error 
No route matches "/relationships" 

가 표시됩니다.

내 관계 컨트롤러에서 나는 모든 propers 메서드를 만들었습니다.

def create  
... 
end 

def destroy  
... 
end 

def update  
... 
end 

def show  
... 
end 

그리고 내 루트 구성에서 관계 컨트롤러의 모든 경로를 허용하도록 설정했습니다.

resources :relationships 

(

:html => {:method => 'delete'} 

메서드 매개 변수를 form_for에서 제거하면 컨트롤러 pb.

메서드가 생성됩니다.

난 이해가 안돼 ....

알렉스

추신 : 이것은 관계에 대한 갈퀴 경로 결과입니다 :

relationships GET /relationships(.:format)   {:action=>"index", :controller=>"relationships"} 
       POST /relationships(.:format)   {:action=>"create", :controller=>"relationships"} 

답변

4

당신은 하나의 리소스에 delete 요청을 가리켜 야이 관계에 대한 레이크 경로 결과입니다 예를 들어. relationships/4325. 어떤 URL/동사 조합이 유효한 지 보려면 rake routes을 실행하십시오. (자체 양식을 작성)

resources :relationships, :only => [:index, :create, :destroy] 

팔로 잉 언 팔로우 버튼 :

는 관계 자원에 대한

경로를 --edit

= button_to "Unfollow", relationship_path(relationship), :method => 'delete' 
+0

좋아, 난 당신이 무슨 뜻인지 볼? 그러나 나는 그것을 어떻게 할 것이냐? 나는 미안해 보이지 않는다. 나는 그 길을 파괴하기 위해 무엇을 바꾸어야할지 모른다. – Alex

+0

@Alex : 예제 추가 – Heikki

+0

Ohh woa .. 그 매력처럼 작동! 정말 고마워 ! – Alex

관련 문제