2013-12-21 2 views
0

"topics_controller"내의 쇼에서 액세스하려고 시도하는 "topics_controller"에서 "createpost"라는 메서드가 있지만 경로 오류가 계속 발생합니다.form_for route error [RoR]

폼 :

는 컨트롤러 액션이
<%= form_for @community_post, :url => { :action => "createpost", :controller=> "community_topics" } do |f| %> 

<%= render 'error_messages' %> 

<%= f.label :text %> 
<%= f.text_area :text %> 

<%= hidden_field_tag :community_topic_id, @community_topic.id %> 

<br> 

<%= f.submit "Submit reply" %> 

: 내가 잘못 뭐하는 거지

def createpost 
    @community_post = CommunityPost.new(community_post_params) 

    @community_post.user_id = current_user.id 
    @community_post.community_topic_id = params[:community_topic_id] 

    if @community_post.save 
     redirect_to "/community_topics/#{@community_post.community_topic_id}", notice: 'Community post was successfully created.' 
    else 
     render action: 'new' 
    end 
    end 

그래서 그것을 수정할 수 있습니까? 무리 감사.

resources :comunity_topics do 
    post 'createpost', action: 'createpost' 
end 

및 양식 경로가 같은 것을해야한다 :

createpost_comunity_topics_path 
+0

이 routes.rb''의 관련 부분을 포함하시기 바랍니다. 'createpost'라는 멤버 액션에 대한 경로가 정의되어 있습니까? –

+0

필자는 필자가 필요하다고 생각하지 않았다. 필자의 응용 프로그램 내에서 누군가를 위해 공개적으로 라우트되지 않아야하기 때문이다. 지금 당장 가지고있는 리소스는 다음과 같습니다. community_topics 리소스 : community_posts와 관련하여 –

+0

적어도 라우팅 오류를 표시 할 수 있습니까? topics_controller와 community_topics 컨트롤러를 지정했습니다. – deepthi

답변

0

당신은 당신의 경로 같은 뭔가에 있어야한다 볼 수있는 form_for. 아니면 정말이 같은 createpost 작업을 사용하려는 경우, 경로를 정의

resources :community_posts do 
    collection do 
    post :createpost 
    end 
end 

을하지만 레일로 컨트롤러와 액션의 이름을 포함 경로를했을 때 당신이 배에서 오래된 튜토리얼을 따르고 있는지 의심 실행. 이 접근법은 RESTful 경로를 위해 폐기되었습니다.

여기에 현재 문서를 읽기 : http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default

0

을 어느 create에 컨트롤러 방법 createpost의 이름을 변경하고 URL 옵션을 제거