我試圖寫公司模型的參數。但是我有錯誤未定義的方法`model_name'爲NilClass:Class在這一點上= simple_form_for @company,url:update_settings_company_path do | f |。我必須在哪裏設置@company?無法將參數寫入模型。 Ruby on Rails
控制器
def change_settings
@vacation_days = current_company.vacation_days
@illnes_days = current_company.illnes_days
end
def update_settings
if @company.update(company_params)
redirect_to account_company_path, notice: t('company.settings_changed')
else
render action: 'change_settings'
end
end
private
def company_params
params.require(:company).permit(:vacation_days, :illnes_days)
end
查看
.company_settings
= simple_form_for @company, url: update_settings_company_path do |f|
= f.error_notification
= f.input :vacation_days
= f.input :illnes_days
%br
= f.submit t('common.save'), class: 'btn'
= link_to t('common.back'), account_company_path, class: 'btn'
路線
resource :company, only: :all do
get :change_settings
post :update_settings
patch :update_settings
end
有什麼不對?請幫助我
我修好了!在視圖中用'current_company'替換'@ company'。並添加了「@company = current_company'來更新方法。 –