Hide DIV [Rails]

Hiding the DIV will be fairly easy in Javascript, but is there any way for Rails-y to do this? I can come up with some ways to do this by calling Javascript from partial (.erb), of course, but I would prefer not to write Javascript at all. Is it possible?

Edit: The page is loaded, and I would like to hide the DIV after the (well, on) Ajax call, so I ended up in one of these render :update .

+7
html ajax ruby-on-rails
source share
5 answers

Or, right in your opinion:

For the div specified in the class:

 <%= link_to_function "Toggle", "$('.some_div').toggle()" %> 

For the identifier specified by ID:

 <%= link_to_function "Toggle", "$('#some_div').toggle()" %> 

(note the hash tag)

Added period to a specific div class and hash to a specific id div

+11
source share
 render :update do |page| page.hide 'div_id' end 

You can throw this in the response block or RJS template.

Another good tip using the same syntax:

 render :update do |page| page << 'arbitrary javascript code goes here.' end 
+6
source share

To upgrade RJS from your controller:

 respond_to do |format| format.html format.js { render(:update) { |page| page.hide('element_id') } } end 

You can find the API for other RJS answers.

+3
source share

I don't really know the rails, but you can simply output something like style = "display: none;" into the div tag?

+1
source share
 <%= link_to_function "Toggle", visual_effect(:toggle_blind, "some_div") %> 
+1
source share

All Articles