2016-08-02 13 views
0

は、私が組織の要求と呼ばれるモデルを持っているRailsの4Railsの4 - ルートおよびパス

にルートやパスを使用する方法を学習しようとしています。

次のように私はroutes.rbをすることによって内のルートを持っている:私の組織では

resources :organisation_requests do #, only: [ :index, :new, :create ] 
    member do 
     put "requested" => "organisation_requests#requested", as: :request_approval #what does this mean? 
     put "approved" => "organisation_requests#requested", as: :approved #what does this mean? 
     put "rejected" => "organisation_requests#rejected", as: :not_approved #what does this mean? 
     put "removed" => "organisation_requests#removed", as: :removed #what does this mean? 
    end 
    end 

は、コントローラを要求し、私が持っている:私の組織では

def approved 
    organisation_request = OrganisationRequest.find(params[:id]) 
    authorize @organisation_request 
    if organisation_request.state_machine.transition_to!(:approved) 
     flash[:notice] = "You've been added as a member. Welcome aboard." 
     format.html { redirect_to :index } 
     # format.json { render :show, status: :ok, location: @project } 
     # redirect_to action: :show, id: project_id 
     # add mailer to send message to owner that article has been approved 
    else 
     flash[:error] = "You're not able to manage this organisation's members" 
     redirect_to(profile_path(current_user.profile)) 
     # redirect_to action: :show, id: project_id 
    end 
    end 

がインデックスを要求し、私が作るしようとしていますユーザーがリクエストを承認できるパス:

<% @organisation_requests.each do |orgReq| %> 

       <tr> 
       <td> 
        <%#= link_to orgReq.profile.user.full_name, organisation_request.profile_path(organisation_request.profile.id) %> 
       </td> 
       <td> 
        <%= orgReq.created_at.try(:strftime, '%e %B %Y') %> 
       </td> 
       <td> 
        <%= orgReq.current_state %> 
       </td> 
       <td> 
        <% if policy(orgReq).approved? %>  
         <%= link_to "APPROVE", request_approval_path(@organisation_request), :class=>'btn btn-info', method: :put %> 
        <% end %> 


       </td> 

       </tr> 
      <% end %> 

これをすべて保存して試してみると、私は期待しています承認ボタンが機能します。代わりに次のようなエラーが表示されます。

undefined method `request_approval_path' for #<#<Class:0x007fa470f72968>:0x007fa474d17a98> 

どこが間違っているのかわかりません。 Railsの4

答えて

0

これは、メソッド名が「request_approval_organisation_request」であるためです。あなたはそのルートをコントローラーを知っていると呼んでいます。あなたのリソースインサイド

get 'exit', to: 'sessions#destroy', as: :logout 

を追加する場合:organisation_requestsをあなたは

logout_organisation_request_path 

などを取得します

0

rake はあなたのURLパスのヘルパーは、すべてあなたのroutes.rbファイルの内容の結果として命名されているかを確認することができますroutesコマンドを持っています。

プロジェクトのルートから、rake routes | grep request_approvalには何が得られますか?

関連する問題