在控制器中获取和发布方法。 Ruby on Rails

时间:2013-09-25 14:54:04

标签: ruby-on-rails haml

我尝试在模型中重写一些数据。 Change_settings是GET方法,update_settings是POST。点击SUBMIT后什么也没发生。数据不会改变。请帮帮我(出了什么问题?

控制器

  def change_settings
    @vacation_days = current_company.vacation_days
    @illnes_days = current_company.illnes_days
  end

  def update_settings
    current_company.update_attribute(:vacation_days, :illnes_days)
    current_company.save
    redirect_to account_company_path, notice: t('company.settings_changed')
  end

change_settings view

.company_settings
  = form_tag update_settings_company_path do
    = field_set_tag do
      = label_tag 'vacation_days'
      = text_field_tag :vacation_days
      = label_tag 'illnes_days'
      = text_field_tag :illnes_days
      %br
      = submit_tag t('common.save'), class: 'btn'
      = link_to t('common.back'), account_company_path, class: 'btn' 

路线

resource :company, only: :all do
    get :account        
    get :change_settings
    post :update_settings
  end

1 个答案:

答案 0 :(得分:0)

取代:

current_company.update_attribute(:vacation_days, :illnes_days)
current_company.save

使用:

current_company.update_attributes(vacation_days: params[:vacation_days], illnes_days: params[:illnes_days] )

基本上,您没有将客户端发送的数据记入帐户