遍历 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 %>
查看(在邀请/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