使用Rails 3.1.0的Rails 3.1的ActiveRecord怪異行爲創建行動
def create
@practice = Practice.new(params[:practice])
respond_to do |format|
if (current_user.practices << @practice rescue false)
pmf = current_user.practices_users.inspect # if this line is removed the following update_attributes method breaks!
current_user.practices_users.last.update_attributes(:admin_flg => true, :first_name => params[:first_name], :last_name => params[:last_name])
format.html { redirect_to home_dashboard_path, notice: 'Practice was successfully created.' }
format.json { render json: @practice, status: :created, location: @practice }
else
format.html { render action: "new" }
format.json { render json: @practice.errors, status: :unprocessable_entity }
end
end
end
當 'PMF = ...' 行不存在,我得到這一行
NoMethodError:
undefined method `update_attributes' for nil:NilClass
當'pmf = ...'行存在,創建操作正常工作。到底是怎麼回事?
當你沒有'pmf ='行時'current_user.practices_users'的大小是多少?這可能是交易還沒有完成 –
當你說「方法打破」,你是什麼意思?什麼是錯誤信息? – CharlieMezak