Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经创建了Posts模型,我想在保存或更新模型时更改 Flash 通知文本。
Posts
我怎么能这样做?谢谢!
在您调用Post方法的控制器操作中执行此操作,例如:
Post
class FooController < ApplicationController def create if Post.create(params) flash.notice 'Post saved' else flash.alert 'Post not saved' end end end
最好让您的模型与控制器和控制器方法(例如 )隔离flash,并在控制器中设置它们。
flash