Ruby on rails 3 从另一个控制器更新模型
我想从“验证”控制器更新“用户”模型,该模型有一个名为“验证\代码\确认”的列 我试过写这个代码Ruby on rails 3 从另一个控制器更新模型,ruby-on-rails-3,ruby-on-rails-3.2,Ruby On Rails 3,Ruby On Rails 3.2,我想从“验证”控制器更新“用户”模型,该模型有一个名为“验证\代码\确认”的列 我试过写这个代码 class VerificationController < ApplicationController def index @user = User.find(params[:id]) if @user.update_attributes(params[:user]) redirect_to @user, :flash => { :suc
class VerificationController < ApplicationController
def index
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
redirect_to @user, :flash => { :success => "Successfully verified." }
else
render :action => 'edit'
end
end
我该怎么做?我在互联网上四处寻找,通过验证控制器更新我的专栏,但我无法更新。您有任何错误吗?另外,如果要更新单个列,请尝试使用
update\u attribute
而不是update\u attributes
。如果没有ID,则找不到用户。那么,作为参数[:ID]
传递的是什么?显然什么都没有?是的。它什么也不通过。
<%= form_for(@user) do |f| %>
<div><%= f.label :verification_code_confirmation %><br />
<%= f.number_field :verification_code_confirmation %></div>
<% end %>
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :verification_code_confirmation, :phone
end
end
if @user.update_attributes(params[:user])