Srinivas M.V.
Srinivas M.V.

Reputation: 6608

How to reload partial pages in Rails using RJS?

Hi Currently i am working on a rails project . where i have to reload a partial page .

For example Create action

 def create
    # Some transaction to the database 
   respond_to do |format|
     format.html {render :text => 'Add post' }
     format.js
   end
  end

In my views posts/create.js.rjs i would like to reload the users/_login.html.erb file This contains the total number of posts or the post's size , when it creates a new post its should reload the partial page _login.html.erb and display the posts incremented size

In create.js.rjs if i use page.reload it reloads the entire page , How to reload only the partial file _login.html.erb inside create.js.rjs .

Upvotes: 0

Views: 4184

Answers (2)

Anand Shah
Anand Shah

Reputation: 14913

Yo could also try

page[:my_div].replace :partial => "/users/login"  

where my_div is the id of element that wraps your login template

Upvotes: 2

Bogdan Gusiev
Bogdan Gusiev

Reputation: 8305

The code will look like:

  page.replace_html "login-block-id", :partial => "users/login"

Where login-block-id is the id of element that wraps your login template

Note that replace_html can accept the same arguments as render do.

Upvotes: 5

Related Questions