Module: JsMessage::ControllerMethods
- Defined in:
- lib/js_message/controller_methods.rb
Instance Method Summary collapse
-
#render_js_message(type, hash = {}) ⇒ Object
Helper to render the js_message response.
Instance Method Details
#render_js_message(type, hash = {}) ⇒ Object
Helper to render the js_message response.
Pass in a type of message (:ok, :error, :redirect) and any other data you need. Default data attributes in the response are:
* html
* message
* to (used for redirects)
Examples:
# Send a successful response with some html
:ok, :html => "<p>It worked!</p>"
# Send a redirect
:redirect, :to => "http://www.google.com"
# Send an error response with a message
:error, :message => "Something broke!"
Of course, if you don’t need other data sent back in the response this works as well:
:ok
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/js_message/controller_methods.rb', line 28 def (type, hash = {}) unless [ :ok, :redirect, :error ].include?(type) raise "Invalid js_message response type: #{type}" end = { :status => type, :html => nil, :message => nil, :to => nil }.merge(hash) = {:json => } [:status] = 400 if type == :error render() end |