我正在研究 Ryan Bates 的 Railscast #124:Beta 邀请。我已经准备好所有代码,但我还没有真正让事情正常工作。当我尝试发送邀请电子邮件时,我收到此消息。
Routing Error
No route matches [POST] "/invitations"
如果我在 Routes.rb 中将资源名称复数,则会出现不同的路由错误。
Routing Error
uninitialized constant InvitationsController
我究竟做错了什么?
这是我的 Routes.rb 文件。
resources :users, :invitation
resources :sessions, :only => [:new, :create, :destroy]
match '/hunts', :to => 'hunts#index'
match '/signup/', :to => 'users#new'
match '/signin', :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy'
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
root :to => "pages#home"
match ':controller(/:action(/:id(.:format)))'
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 root_path
else
flash[:notice] = "Thank you, we will notify when we are ready."
redirect_to root_path
end
else
render :action => 'new'
end
end
end
更新:这是要求的信息。意见/邀请/html.erb
<%= 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 %>