我是铁轨新手,卡在奇怪的路口。问题与路线有关。下面是我的代码
路线$
resources :users do
resources :requests
end
用户.rb
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :email, :firstname, :lastname, :state, :city, :password
has_many :requests ,:foreign_key => :user_id,:autosave => :true
请求.rb
class Request < ActiveRecord::Base
attr_accessible :email, :status, :user_id,:token
belongs_to :user
请求表单html
<%= form_for (user_requests_path) do |f| %>
<div class="field">
<%= f.label "Email" %><br />
<div class="fieldgroup">
<%= f.text_field :email , :class=>"textfield"%>
</div>
<div id="spacer">
</div>
<div class="fieldgroup">
<%= f.submit "Invite", :class=>"custombutton" %>
</div>
<% end %>
</div>
当我单击请求表单下的邀请按钮时,我遇到了以下错误,而不是调用 request#create。
路由错误
No route matches [POST] "/users/9/requests/new"
请求控制器
def create
@user = User.find(params[:user_id])
@request = @user.requests.create(params[:request])
redirect_to user_path(@user)
end