我在任何地方都看到過這個問題,但它永遠不能解決我的問題。繼承人我的控制器:無法爲UserVacationDaysController找到'創建'動作
class UserVacationDaysController < ApplicationController
def new
@user = current_user
@user_vacation_days = UserVacationDay.new
end
def create
@user_vacation_days = UserVacationDay.create(params[:user_vacation_day])
@user_vacation_days.user = current_user
# @user_vacation_days.calculate_work_days
# (another param that holds date range will get passed in)
# puts @user_vacation_days.errors.inspect
if @user_vacation_days.persisted?
flash[:notice] = "Request Sent"
redirect_to dashboard_index_path
request_vacation_days # method from model. model method calls method in employee_mailer
else
flash[:notice] = "Something went wrong, please try again"
render :new
end
end
end
這裏是我的看法(表單)。
<h2>Request Days Off</h2>
<%= form_for :user_vacation_days, :url => user_vacation_days_path do |f| %>
<div><%= f.label "How much time off would you like to take?" %>
<%= f.number_field :number_of_days %></div>
<div><%= f.label "Argue your case, slave" %>
<%= f.text_area :description %></div>
<div><%= f.submit "Request Time Off" %></div>
<% end %>
的路線我的2種控制器方法
user_vacation_days POST /user_vacation_days(.:format) user_vacation_days#create
new_user_vacation_day GET /user_vacation_days/new(.:format) user_vacation_days#new
沒有人有任何想法是怎麼回事?我看遍了各處,我找不到任何東西。我想不出爲什麼控制器方法不會被找到。謝謝!
你可以在你的form_for中添加':method =>'POST''並查看它是否清除了它? –
奇怪..你嘗試重新啓動你的Rails服務器嗎? – Benj
我重新啓動了rails服務器,它工作。謝謝本 – Mike