Tag: updatemodel

使用复选框/错误数量的参数rails 4更新一个表单中的多个记录

我一直在通过教程/论坛笨拙地试图弄清楚如何使用复选框更新多个方法。 如果日期可用,我需要能够列出我的“事件”并检查或取消选中它们。 我想在一个表格上这样做。 我知道这是可能的,但是我终于在没有让它工作的时候来到这里。 使用我发布的代码,我得到“错误的参数数量,2比1”错误。 我试过这些信息来源: http : //railscasts.com/episodes/52-update-through-checkboxes http://discuss.codeschool.io/t/surviving-apis-with-rails-posting-multiple-records / 4776/4 http://railscasts.com/episodes/165-edit-multiple-revised 这就是我在的地方 的routes.rb resources :events do collection do put :verified post :make_events end end events_controller.rb def verified if Event.update_all([“available”, true], :id => params[:event_ids]) redirect_to step2_path(:pid => @project.id, :u => current_user.id) else end end show.html.erb @project.id ), method: :put do %> event.available %> ‘btn […]

Rails update_attributes方法是否是在数据库中更新模型的最佳选择?

def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>’list’) else render(:action=>’edit’) end end 我正在讨论的Rails 1.1.6教程建议使用update_attributes方法更新模型,如上面列出的控制器的示例代码中所示。 看看Rails文档,我想知道为什么update方法不是首选,特别是因为它的逻辑命名。