Hiding a DIV would be easy enough in Javascript, but is there some Rails-y way to do it? I can think of some ways to do it by calling Javascript from a partial (.erb), of course, but I'd prefer not to write any Javascript at all. Possible?
Edit: The page is loaded and I would like to hide the DIV after (well, on) an Ajax call, so I'm in one of those render :update
blocks.
Or, right in your view:
For a class-specified div:
<%= link_to_function "Toggle", "$('.some_div').toggle()" %>
For an ID-specified div:
<%= link_to_function "Toggle", "$('#some_div').toggle()" %>
(notice the hash-mark)
Added period to class specific div and hash to id specific div
render :update do |page|
page.hide 'div_id'
end
You can throw this in you respond_to block or an RJS template.
Another helpful tip, using the same syntax:
render :update do |page|
page << 'arbitrary javascript code goes here.'
end
To render an RJS update from your controller:
respond_to do |format|
format.html
format.js { render(:update) { |page| page.hide('element_id') } }
end
You can look up the API for other RJS responses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With