I have a method in my controller like the following (the syntax may not
be correct, I''m doing this from memory - you should be able to get the
idea though) My rhtml page has a DIV with id="country_areas", which
contains a partial that only makes a drop down of country areas for a
specific country. When changing the country in the country drop down, it
uses the :observe_field to call the below method and refresh the
country_areas partial.
def find_country_areas
@country_areas = Country.find(:all, :condition => ("country_id
=?",
params[:country_id]) )
render :partial => "country_areas", :object => @country_areas
end
The country areas drop down is getting changed to reflect those country
areas that are for a specific country, so all is well.
Now if I change the above method to:
def find_country_areas
@country_areas = Country.find(:all, :condition => ("country_id
=?",
params[:country_id]) )
end
and use a find_country_areas.rjs:
page.relace ''country_areas'', :partial =>
''country_areas'', :object =>
''@country_areas''
it works correctly the first time I change a country. But any subsequent
changes to the country drop down do not re-render the partial at all (ie
the same areas are populated as the first country I selected). My method
is getting called, but no refresh of the partial.
Why do these behave differently? I want to use rjs because ultimately I
have two partials that I want to refresh.
Thanks
Brian
--
Posted via http://www.ruby-forum.com/.
Francois Beausoleil
2006-May-17 15:44 UTC
[Rails] RJS behave differently than render :partial?
Hi ! 2006/5/17, Brian Nice <bnice_99@yahoo.com>:> page.relace ''country_areas'', :partial => ''country_areas'', :object => > ''@country_areas''Don''t pass a string as the object, but do pass the instance variable. page.relace ''country_areas'', :partial => ''country_areas'', :object => @country_areas Notice no apostrophes around@contry_areas. You had an error because your partial was receiving a String object when it expected an Enumerable. Bye ! -- Fran?ois Beausoleil http://blog.teksol.info/
Fran?ois Beausoleil wrote:> Hi ! > > 2006/5/17, Brian Nice <bnice_99@yahoo.com>: >> page.relace ''country_areas'', :partial => ''country_areas'', :object => >> ''@country_areas'' > > Don''t pass a string as the object, but do pass the instance variable. > > page.relace ''country_areas'', :partial => ''country_areas'', > :object => @country_areas > > Notice no apostrophes around@contry_areas. You had an error because > your partial was receiving a String object when it expected an > Enumerable. > > Bye !I think that is the way I have it - without quotes (sorry trying to remember something that is at home while I am at work). Otherwise, I don''t think it would even work the first time. Is there anything else that would cause these to work differently? -- Posted via http://www.ruby-forum.com/.
Michael Trier
2006-May-17 17:39 UTC
[Rails] Re: RJS behave differently than render :partial?
Look at the generated code and you should see the difference. I imagine it''s the difference between one replacing the innerHTML and the other the outerHTML. Note that render :partial is not the same things as page.replace. Michael