I am having a little problem with the rendering of partials and form helpers. Either i am missing something or this just cannot be done. Here is my contrived example.. here is the partial _address.rhtml <%= text_area( ''address'', ''street'') %> Now if i want to render this i do like so... #get a user object @user = User.find_by_id(1) @address = User.address render :partial=>''address''} this produces... <textarea id="address_street" name="address[street]">Front St.</textarea> Now if i want to pass in the object to the partial... #get a user object @user = User.find_by_id(1) render :partial=>''address'', :object=>User.address} this produces... <textarea id="address_street" name="address[street]"></textarea> In the second example where i passed in the object, i can access it and print values by doing like so in _address.rhtml <textarea><%= address.street %></textarea> I want to be able to stick to using the form helpers, but still pass in the object without having to declare @address. Is this possible? Any ideas besides putting this line in the partial?: <% @address = address %> Thanks in advance for any help, mark -- Mark Van Holstyn mvette13-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://lotswholetime.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Mark try: render :partial => ''address'' :locals => {:address => User.address} On Nov 9, 2005, at 1:51 PM, Mark Van Holstyn wrote:> I am having a little problem with the rendering of partials and > form helpers. Either i am missing something or this just cannot be > done. Here is my contrived example.. > > here is the partial _address.rhtml > > <%= text_area( ''address'', ''street'') %> > > > Now if i want to render this i do like so... > > #get a user object > @user = User.find_by_id(1) > @address = User.address > render :partial=>''address''} > > this produces... > > <textarea id="address_street" name="address[street]">Front St.</ > textarea> > > Now if i want to pass in the object to the partial... > > #get a user object > @user = User.find_by_id(1) > render :partial=>''address'', :object=>User.address} > > this produces... > > <textarea id="address_street" name="address[street]"></textarea> > > In the second example where i passed in the object, i can access it > and print values by doing like so in _address.rhtml > > <textarea><%= address.street %></textarea> > > I want to be able to stick to using the form helpers, but still > pass in the object without having to declare @address. Is this > possible? > > Any ideas besides putting this line in the partial?: > <% @address = address %> > > > Thanks in advance for any help, > > mark > > -- > Mark Van Holstyn > mvette13-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > http://lotswholetime.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Mark Van Holstyn wrote:> > Now if i want to pass in the object to the partial... > > #get a user object > @user = User.find_by_id(1) > render :partial=>''address'', :object=>User.address} >there is no :object User.address isnt on an object you want @user.address and the } hanging out by itself is an error. the form you want is: # Renders the same partial but also makes a local variable available to it render :partial => "win", :locals => { :name => "david" } or in your case render :partial => ''address'', :locals => { :address => @user.address } see http://api.rubyonrails.com/classes/ActionController/Base.html#M000171 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi ! 2005/11/9, Jeff Smick <rails_lists@hardcorpsfans.org>:> render :partial => 'address' :locals => {:address => User.address}That won't work either, because the form helper functions expect an instance variable to be available. It has nothing to do whatsoever with having or not a partial in the picture. Hope that helps ! François _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> > > That won''t work either, because the form helper functions expect an > instance variable to be available. It has nothing to do whatsoever > with having or not a partial in the picture. >That is correct. I guess my subject line was a little off base. It is actully the form helper that is expecting the instance variable. Is there a way to change what the form helper looks at? Mark -- Mark Van Holstyn mvette13-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://lotswholetime.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
<% @address = address %> is the basic of it. Mark Van Holstyn wrote:> > That won''t work either, because the form helper functions expect an > instance variable to be available. It has nothing to do whatsoever > with having or not a partial in the picture. > > > That is correct. I guess my subject line was a little off base. It is > actully the form helper that is expecting the instance variable. Is > there a way to change what the form helper looks at? > > Mark > > > -- > Mark Van Holstyn > mvette13-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mailto:mvette13-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > http://lotswholetime.com > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails