glarkou
glarkou

Reputation: 7101

Show a Notification in Rails after updating a Model

Is it possible to use the ActiveRecord Callbacks

to display notifications using jquery to the user?

Can someone provide an example??

Thanks

Upvotes: 0

Views: 625

Answers (1)

Cimm
Cimm

Reputation: 4775

It's not the responsibility of the model to comunicate back to the view. In my opinion this should be handled in the controller, not the model. The controller could look like:

respond_to :json
def create
  if @page.save
    respond_with {:message => "Aye Okay!"}
  else
    respond_with {:message => "Oops, something went wrong."}
  end
end

The destroy and before create cases could follow the same idea: check manually in the controller and send the message from there.

Not exactly what you asked but I think you should keep them separated.

Upvotes: 4

Related Questions