0
我有以下的在我的Rails創建操作3控制器:Rails的驗證登錄的管理員用戶時無法
def create
@registration = Registration.new(params[:registration])
respond_to do |format|
if @registration.save
if @registration.orientation != nil #TODO replace this with an online? method
format.html { render "scheduling_text.html.erb" }
format.json { render json: @registration, status: :created, location: @registration }
NsoMailer.registration_email(@registration).deliver
else
format.html { render "online_scheduling_text.html.erb" }
format.json { render json: @registration, status: :created, location: @registration }
NsoMailer.online_registration_email(@registration).deliver
end
else
format.html { render action: "new" }
format.json { render json: @registration.errors, status: :unprocessable_entity }
end
end
end
我有我自己的身份驗證的地方,當我沒有登錄到應用我的驗證按照他們應該的工作。這就是說我把它放在上面代碼的respond_to塊中。然而,作爲身份驗證的用戶,如果我嘗試並提交這種形式,我的驗證失敗,此錯誤...
Started POST "/registrations" for 127.0.0.1 at 2014-06-11 09:52:13 -0400
Processing by RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"PJMFr2FYTYszVndofuZZTaFTmwN8C/41oc6h7ldqfKA=", "registration"=>{"orientation_id"=>"3", "first_name"=>"", "last_name"=>"", "email"=>"", "student_id"=>"", "phone"=>"", "program"=>""}, "commit"=>"Register"}
(0.1ms) begin transaction
(0.0ms) rollback transaction
Rendered registrations/_form.html.erb (6.4ms)
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
Rendered registrations/new.html.erb within layouts/application (8.4ms)
Completed 500 Internal Server Error in 16ms
ActionController::RoutingError (No route matches {:controller=>"registrations"}):
app/views/registrations/new.html.erb:9:in `_app_views_registrations_new_html_erb__773571217_97879480'
app/controllers/registrations_controller.rb:64:in `block (2 levels) in create'
app/controllers/registrations_controller.rb:52:in `create'
Rendered /home/johnmlocklear/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.5ms)
這似乎有事情做與路由?正如順便說一句我的路線看起來像......
/orientations/3/registrations/new
當窗體最初加載,並經過驗證失敗的路線是...
/registrations
...用的orientation_id隱藏值。不知道這將與用戶登錄有什麼關係。另外請注意,錯誤中有一行可以重新加載用戶。我沒有看到,當我沒有登錄,這也可能是問題的一部分。
任何幫助表示讚賞!
編輯
這裏的應用程序/視圖/註冊/ new.html.erb
<h1>Register for New Student Orientation</h1>
<%= render 'form' %>
<%= link_to 'Back', orientations_path %>
<% if current_user %>
</br>
<%= link_to 'View Registrations', orientation_registrations_path %>
<%end%>
這裏是orientation_registrations路線...
orientation_registrations GET /orientations/:orientation_id/registrations(.:format) registrations#index
POST /orientations/:orientation_id/registrations(.:format) registrations#create
你可以發表你的表格。 –
是的......見上面! – Lumbee
「app/views/registrations/new.html.erb」的第9行是什麼?因爲這是錯誤的地方,我認爲你是你的形式,但我什麼都看不到 –