0

MVC を見て、すべてが正しく設定されているかどうかを確認するための最良の (最も簡単な) 方法は何ですか?

私は少し困惑しており、次のようなエラー メッセージを簡単に修正する必要があると感じています。

undefined method `invitations_path' for #<#<Class:0x00000105ad5cb8>:0x00000105820b30>

アプリに少量のコードを追加した後、問題が発生したため、自分でトラブルシューティングしたいと考えています。

ヒントをありがとう!

編集

おそらく、特定の問題のトラブルシューティングは、一般化されたアプローチにつながるでしょう。

  • Link_to は<% %> の代わりに使用された <%= %> をリンクしていません。
  • 上記のエラーは、localhost:3000/invitation/new にアクセスすると生成されます

ビュー(home/index.erb.html 内)

<% if @user.invitation_limit > 0 %>
        <% link_to 'Send Invitations', new_invitation_path %> 
        (<%= @user.invitation_limit %> left)
<% end %>

ビュー(invitation/new.erb.html 内)

<%= error_messages_for :invitation %>
<% form_for @invitation do |f| %>
  <p>
    <%= f.label :recipient_email, "Friend's email address" %><br />
    <%= f.text_field :recipient_email %>
  </p>
  <p><%= f.submit "Invite!" %></p>
<% end %>

コントローラ

class InvitationController < ApplicationController
  def new
    @invitation = Invitation.new
  end

def create
    @invitation = Invitation.new(params[:invitation])
    @invitation.sender = current_user
    if @invitation.save
      if logged_in?
        Mailer.deliver_invitation(@invitation, signup_url(@invitation.token))
        flash[:notice] = "Thank you, invitation sent."
        redirect_to projects_url
      else
        flash[:notice] = "Thank you, we will notify when we are ready."
        redirect_to root_url
      end
    else
      render :action => 'new'
    end
  end
end

モデル

class Invitation < ActiveRecord::Base
  belongs_to :sender, :class_name => 'User'
  has_one :recipient, :class_name => 'User'

  attr_accessible :recipient_email, :sender_id, :sent_at, :token
end

ルート.rb

resources :home, :only => :index
resources :invitation
4

1 に答える 1

0

コントローラー アクションごとにリクエスト仕様を作成できます。リクエスト スペックは、コントローラーからビューのレンダリングまでリクエストに従います。エラーが発生した場合は、リクエスト スペックに表示されます。

これには設定に時間がかかる場合がありますが、Web サイトの新しいバージョンを公開するときにすべてのページを手動でテストする必要がないため、将来的には多くの時間を節約できます。

于 2013-06-23T06:21:22.417 に答える