Hi, I am seing a behaviour that I would qualify as strange :) But maybe that''s due to my lack of understanding of the whole framework (this is on the works, as I got the book and working on some rails project is enlightening me :) ). I am currently working from Rails on SVN, ruby 1.8.2 ... I have a view that has a link_to_remote that calls an action in another controller and updates a DIV in that same page (AJAX). That part works fine. The action that''s called displays a form. The problem seems to be when I place "render(:layout => false)" (or pre my latest update "render_without_layout") in that action, I get errors about a method that''s not available. But if I ommit this render(:layout => false), everything is fine. The action is: def new render(:layout => false) @all_countries = Country.find_all() @client = Client.new end That''s part of my ClientController. My Client model has: belongs_to :country And in the view for "new" I have: <select id="client_country_id" name="client[country_id]"> <%= options_from_collection_for_select(@all_countries, "id", "default_name", (@client.country.id unless @client.country.nil?)) %> </select> One of these "country" is generating an error when I am calling the URL: NoMethodError in Client#new Showing /client/new.rhtml where line #17 raised: undefined method `country'' for nil:NilClass Extracted source (around line #17): 14: <%= text_field "client", "state", :size => 10 %> 15: <label for="client_country_id">Country:</label><br /> 16: <select id="client_country_id" name="client[country_id]"> 17: <%= options_from_collection_for_select(@all_countries, "id", "default_name", (@client.country.id unless @client.country.nil?)) %> 18: </select> 19: <br /><br /> 20: <%= submit_tag "Create" %> Again, if I remove the "render" call, it displays correctly (well, with the whole layout in that DIV, which is not what I want). Any hints? :) Thanks in advance, /B -- Bruno Mattarollo <bruno.mattarollo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Currently in: Sydney, Australia
Bruno Mattarollo wrote:> Any hints? :)Have you tried writing the render command as the last statement in the action method? rgds Dema -- http://dema.ruby.com.br - Rails development from a .NET perspective
Hey Bruno, On 6.6.2005, at 14:12, Bruno Mattarollo wrote:> > The action that''s called displays a form. The problem seems to be when > I place "render(:layout => false)" (or pre my latest update > "render_without_layout") in that action, I get errors about a method > that''s not available. But if I ommit this render(:layout => false), > everything is fine. > > The action is: > > def new > render(:layout => false) > @all_countries = Country.find_all() > @client = Client.new > endI think render call should be the last line of the action, at least that would make most sense. If you omit the render call, it''s called implicitly as the last thing in that action (with default parameters, of course). Not sure but I think that might be the source of your problem. You''re now calling render before you have @client set, that''s why the view file bombs. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks Demetrius and Jarkko. It had to be something that simple ... of course, after a whole day of work, coming home and working on this is not the recommended way of doing things :) Thanks again! /B On 6/6/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> Hey Bruno, > > On 6.6.2005, at 14:12, Bruno Mattarollo wrote: > > > > The action that''s called displays a form. The problem seems to be when > > I place "render(:layout => false)" (or pre my latest update > > "render_without_layout") in that action, I get errors about a method > > that''s not available. But if I ommit this render(:layout => false), > > everything is fine. > > > > The action is: > > > > def new > > render(:layout => false) > > @all_countries = Country.find_all() > > @client = Client.new > > end > > I think render call should be the last line of the action, at least > that would make most sense. If you omit the render call, it''s called > implicitly as the last thing in that action (with default parameters, > of course). Not sure but I think that might be the source of your > problem. You''re now calling render before you have @client set, that''s > why the view file bombs. > > //jarkko > > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > >-- Bruno Mattarollo <bruno.mattarollo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Currently in: Sydney, Australia