2015-04-05 50 views
0

我想在方法模型中保存這些值,但它不能保存。我不知道我是否要使用text_field_tag或其他東西。使用參數,但我不能得到價值

查看:

<div class="field"> 
    <%= f.label 'Nemónico' %> 
    <%= f.text_field :nemo %> 
</div> 

控制器:

n = params[:nemo] 
Change.saveHist(current_user.email,n,DateTime.now.to_date) 

型號:

def self.saveHist(session,nemo,date) 
    h = DawHist.create(hsesion: session, hregnemo: nemo,hdate: date) 
end 
+0

Rails's'development.log'中的參數hash的內容是什麼? – 2015-04-05 17:07:07

+0

使用create!而不是通過創建來了解錯誤。你可能有驗證錯誤 – 2015-04-05 17:21:11

+0

@architgupta我dit它和日誌中的錯誤是 'ActiveRecord :: RecordInvalid(驗證失敗:nemo不能爲空): app/models/change.rb:8:in saveHit' app/controllers/registrers_controller.rb:52:在block中更新' app/controllers/registrers_controller.rb:48:in update'' – vimx 2015-04-05 17:45:33

回答

2

根據您的發佈參數,可以,你需要在你的情況下使用該模型的名稱(Register我猜)

因此,當你使用params[:register][:nemo]時,你應該沒問題。

+0

使用'params [:register] [nemo]' 謝謝! – vimx 2015-04-05 18:04:50