Rails 3.1.0 の使用
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 = ...」行が存在する場合、作成アクションは正常に機能します。何が起こっている?