【发布时间】:2012-04-07 17:49:14
【问题描述】:
我正在研究 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 %>
【问题讨论】:
-
请用查看代码更新您的问题
标签: ruby-on-rails rails-routing