Ruby on rails 传入对象时,在Rails模型方法中找不到感叹号
使用Rails 3.2。我有以下邮件操作:Ruby on rails 传入对象时,在Rails模型方法中找不到感叹号,ruby-on-rails,Ruby On Rails,使用Rails 3.2。我有以下邮件操作: # shop.rb class Shop < ActiveRecord::Base def deliver_update_notification!(user) version = self.versions(user).last EditorMailer.updated_spot(self, version).deliver end end # shops_controller.rb class ShopsContr
# shop.rb
class Shop < ActiveRecord::Base
def deliver_update_notification!(user)
version = self.versions(user).last
EditorMailer.updated_spot(self, version).deliver
end
end
# shops_controller.rb
class ShopsController < ApplicationController
def update
@shop = Shop.find(params[:id])
if @shop.update_attributes(params[:shop])
@shop.deliver_update_notification!(current_user)
redirect_to shop_path(@shop)
else
render 'edit'
end
end
end
#shop.rb
类Shop
不知何故,当我将当前用户
对象传递给方法传递更新通知时代码>,它抛出一个错误,表示找不到该方法。如果将方法更改为不接受任何对象,则该方法有效。为什么会这样
另外,我不记得为什么我在方法中有感叹号。从某处看到的。感叹号的作用是什么
谢谢。感叹号应该表示该方法“危险”,并编辑调用该方法的对象的值。不知道如何定义bang方法,但您始终可以不使用“!”感叹号的作用是指明你正在进行破坏性的操作(要么你正在修改对象,要么你正在做一些无法撤消的操作)。至于你的另一个问题。。。我不知道,你不是保存了商店文件还是什么?看起来应该有用