Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
rjs drying-up problem
2 Posts
rjs drying-up problem

The following are the code snippets of the situation. Its about the rjs.



Home

The returned html via /order/new is as follows:

Email
Phone
First Name
Last Name

When this remote form is submitted, the 'create' method of the OrdersController is fired and the code which tries to update the div with the id #flash_messages of the main layout is as follows:

    .....
    render :update do |page|
        page.replace "flash_messages", "Error checking out. Re-order again!!"
    end
    ......

And the RJS error is "RJS error, TypeError: element is null". And its because of the call:

    page.replace "flash_messages"

Since, the

is still in the main-layout of the index page, why can't the "page.replace" get that element? If I put the
in the updated html sent via "/order/new" action, the page.replace "flash_messages" works. But if I got to do that, then it won't be dry coz I got to put it in every Ajax.Updater call?? So, how could I access the #flash_messages of the main-layout to make it dry?

Try using "page.replace_html":http://apidock.com/rails/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods/replace_html instead of page.replace. This will replace the innerHTML of the '#flash_messages' div and you won't lose the div.

2 Posts
Login to add your message