Hi All, New to the group, and new to learning rails. I''m having some trouble, i''ve done a few tutorials on creating some small apps with rails and am now starting to play around myself. I''ve been trying to create a simple form which when a user enters any data that data is displayed as a preview elsewhere on the page instantly, just like when creating an advert with Google Adwords, the preview is shown. I''ve been using form_remote_for and observe_form but I don''t seem to be having much luck at all. I am unsure how to use the controller to get the form fields and pass them back to a partial to be rendered? Here is my form: <% form_remote_for @advert do |a| %> <label>Title:</label> <%= a.text_field :title %> <br /> <label>First Line:</label> <%= a.text_field :first_line %> <br /> <label>Second Line:</label> <%= a.text_field :second_line %> <br /> <label>Visible URL:</label> <%= a.text_field :visible_url %> <br /> <label>Destination URL:</label> <%= a.text_field :destination_url %> <%= submit_tag ''Submit'' %> <% end %> Any help would be great? Cheers, Phil --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 1, 1:04 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> > I''ve been trying to create a simple form which when a user enters any > data that data is displayed as a preview elsewhere on the page > instantly, just like when creating an advert with Google Adwords, the > preview is shown. > > I''ve been using form_remote_for and observe_form but I don''t seem to > be having much luck at all. I am unsure how to use the controller to > get the form fields and pass them back to a partial to be rendered? >In this respect it''s much like a normal form, eg the title will be params[:advert][:title] (assuming @advert is of class Advert). As usual you can just looking at development.log to see what the parameters look like. Fred> Here is my form: > > <% form_remote_for @advert do |a| %> > <label>Title:</label> <%= a.text_field :title %> > <br /> > <label>First Line:</label> <%= a.text_field :first_line %> > <br /> > <label>Second Line:</label> <%= a.text_field :second_line %> > <br /> > <label>Visible URL:</label> <%= a.text_field :visible_url %> > <br /> > <label>Destination URL:</label> <%= a.text_field :destination_url %> > <%= submit_tag ''Submit'' %> > <% end %> > > Any help would be great? > > Cheers, > > Phil--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
So then do I need to use the controller to populate another @advert object with all the params then render the partial? Cheers, Phil On Mar 1, 5:00 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 1, 1:04 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > > I''ve been trying to create a simple form which when a user enters any > > data that data is displayed as a preview elsewhere on the page > > instantly, just like when creating an advert with Google Adwords, the > > preview is shown. > > > I''ve been using form_remote_for and observe_form but I don''t seem to > > be having much luck at all. I am unsure how to use the controller to > > get the form fields and pass them back to a partial to be rendered? > > In this respect it''s much like a normal form, eg the title will be > params[:advert][:title] (assuming @advert is of class Advert). As > usual you can just looking at development.log to see what the > parameters look like. > > Fred > > > Here is my form: > > > <% form_remote_for @advert do |a| %> > > <label>Title:</label> <%= a.text_field :title %> > > <br /> > > <label>First Line:</label> <%= a.text_field :first_line %> > > <br /> > > <label>Second Line:</label> <%= a.text_field :second_line %> > > <br /> > > <label>Visible URL:</label> <%= a.text_field :visible_url %> > > <br /> > > <label>Destination URL:</label> <%= a.text_field :destination_url %> > > <%= submit_tag ''Submit'' %> > > <% end %> > > > Any help would be great? > > > Cheers, > > > Phil--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 1, 5:10 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> So then do I need to use the controller to populate another @advert > object with all the params then render the partial? >Well I don''t know exactly what this controller is trying to do at all. Assuming what it''s doing is create a new object then the controller code is almost exactly the same as a regular create action, the only difference is that instead of redirecting to the show action you''re rendering a partial for the object you''ve just created. Fred> Cheers, > > Phil > > On Mar 1, 5:00 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Mar 1, 1:04 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > I''ve been trying to create a simple form which when a user enters any > > > data that data is displayed as a preview elsewhere on the page > > > instantly, just like when creating an advert with Google Adwords, the > > > preview is shown. > > > > I''ve been using form_remote_for and observe_form but I don''t seem to > > > be having much luck at all. I am unsure how to use the controller to > > > get the form fields and pass them back to a partial to be rendered? > > > In this respect it''s much like a normal form, eg the title will be > > params[:advert][:title] (assuming @advert is of class Advert). As > > usual you can just looking at development.log to see what the > > parameters look like. > > > Fred > > > > Here is my form: > > > > <% form_remote_for @advert do |a| %> > > > <label>Title:</label> <%= a.text_field :title %> > > > <br /> > > > <label>First Line:</label> <%= a.text_field :first_line %> > > > <br /> > > > <label>Second Line:</label> <%= a.text_field :second_line %> > > > <br /> > > > <label>Visible URL:</label> <%= a.text_field :visible_url %> > > > <br /> > > > <label>Destination URL:</label> <%= a.text_field :destination_url %> > > > <%= submit_tag ''Submit'' %> > > > <% end %> > > > > Any help would be great? > > > > Cheers, > > > > Phil--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I am simply trying to show what the user enters somewhere else on the page as they type it. I did get it to work using render :text => param[:advert][:title] + ''<br/>'' + param[:advert][:first_line] ...... But I think there should be a more efficient way to do it? Could I do something like this: def preview @advert = Advert.new(params[:advert]) render :partial => ''advert'' end Phil On Mar 1, 7:31 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 1, 5:10 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > So then do I need to use the controller to populate another @advert > > object with all the params then render the partial? > > Well I don''t know exactly what this controller is trying to do at all. > Assuming what it''s doing is create a new object then the controller > code is almost exactly the same as a regular create action, the only > difference is that instead of redirecting to the show action you''re > rendering a partial for the object you''ve just created. > > Fred > > > > > Cheers, > > > Phil > > > On Mar 1, 5:00 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On Mar 1, 1:04 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > > I''ve been trying to create a simple form which when a user enters any > > > > data that data is displayed as a preview elsewhere on the page > > > > instantly, just like when creating an advert with Google Adwords, the > > > > preview is shown. > > > > > I''ve been using form_remote_for and observe_form but I don''t seem to > > > > be having much luck at all. I am unsure how to use the controller to > > > > get the form fields and pass them back to a partial to be rendered? > > > > In this respect it''s much like a normal form, eg the title will be > > > params[:advert][:title] (assuming @advert is of class Advert). As > > > usual you can just looking at development.log to see what the > > > parameters look like. > > > > Fred > > > > > Here is my form: > > > > > <% form_remote_for @advert do |a| %> > > > > <label>Title:</label> <%= a.text_field :title %> > > > > <br /> > > > > <label>First Line:</label> <%= a.text_field :first_line %> > > > > <br /> > > > > <label>Second Line:</label> <%= a.text_field :second_line %> > > > > <br /> > > > > <label>Visible URL:</label> <%= a.text_field :visible_url %> > > > > <br /> > > > > <label>Destination URL:</label> <%= a.text_field :destination_url %> > > > > <%= submit_tag ''Submit'' %> > > > > <% end %> > > > > > Any help would be great? > > > > > Cheers, > > > > > Phil- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 1, 7:38 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> I am simply trying to show what the user enters somewhere else on the > page as they type it. > > I did get it to work using render :text => param[:advert][:title] + > ''<br/>'' + param[:advert][:first_line] ...... > > But I think there should be a more efficient way to do it? > > Could I do something like this: > > def preview > @advert = Advert.new(params[:advert]) > render :partial => ''advert'' > end >Something like that is fine (although you''ll need to tell rails to use the @advert object). It''s not more efficient in terms of raw cpu cycles but I''m assuming that''s not what you meant (it is a lot easier on the eye and a better separation of presentation from your actual code). Fred> Phil > > On Mar 1, 7:31 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Mar 1, 5:10 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > So then do I need to use the controller to populate another @advert > > > object with all the params then render the partial? > > > Well I don''t know exactly what this controller is trying to do at all. > > Assuming what it''s doing is create a new object then the controller > > code is almost exactly the same as a regular create action, the only > > difference is that instead of redirecting to the show action you''re > > rendering a partial for the object you''ve just created. > > > Fred > > > > Cheers, > > > > Phil > > > > On Mar 1, 5:00 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > On Mar 1, 1:04 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > > > I''ve been trying to create a simple form which when a user enters any > > > > > data that data is displayed as a preview elsewhere on the page > > > > > instantly, just like when creating an advert with Google Adwords, the > > > > > preview is shown. > > > > > > I''ve been using form_remote_for and observe_form but I don''t seem to > > > > > be having much luck at all. I am unsure how to use the controller to > > > > > get the form fields and pass them back to a partial to be rendered? > > > > > In this respect it''s much like a normal form, eg the title will be > > > > params[:advert][:title] (assuming @advert is of class Advert). As > > > > usual you can just looking at development.log to see what the > > > > parameters look like. > > > > > Fred > > > > > > Here is my form: > > > > > > <% form_remote_for @advert do |a| %> > > > > > <label>Title:</label> <%= a.text_field :title %> > > > > > <br /> > > > > > <label>First Line:</label> <%= a.text_field :first_line %> > > > > > <br /> > > > > > <label>Second Line:</label> <%= a.text_field :second_line %> > > > > > <br /> > > > > > <label>Visible URL:</label> <%= a.text_field :visible_url %> > > > > > <br /> > > > > > <label>Destination URL:</label> <%= a.text_field :destination_url %> > > > > > <%= submit_tag ''Submit'' %> > > > > > <% end %> > > > > > > Any help would be great? > > > > > > Cheers, > > > > > > Phil- Hide quoted text - > > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Fred, How would I then need to tell rails to use the @advert object because that''s the part that I have been having trouble with? Phil On Mar 1, 7:41 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 1, 7:38 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> I am simply trying to show what the user enters somewhere else on the > > page as they type it. > > > I did get it to work using render :text => param[:advert][:title] + > > ''<br/>'' + param[:advert][:first_line] ...... > > > But I think there should be a more efficient way to do it? > > > Could I do something like this: > > > def preview > > @advert = Advert.new(params[:advert]) > > render :partial => ''advert'' > > end > > Something like that is fine (although you''ll need to tell rails to use > the @advert object). It''s not more efficient in terms of raw cpu > cycles but I''m assuming that''s not what you meant (it is a lot easier > on the eye and a better separation of presentation from your actual > code). > > Fred > > > > > Phil > > > On Mar 1, 7:31 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On Mar 1, 5:10 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > > So then do I need to use the controller to populate another @advert > > > > object with all the params then render the partial? > > > > Well I don''t know exactly what this controller is trying to do at all. > > > Assuming what it''s doing is create a new object then the controller > > > code is almost exactly the same as a regular create action, the only > > > difference is that instead of redirecting to the show action you''re > > > rendering a partial for the object you''ve just created. > > > > Fred > > > > > Cheers, > > > > > Phil > > > > > On Mar 1, 5:00 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > wrote: > > > > > > On Mar 1, 1:04 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > > > > I''ve been trying to create a simple form which when a user enters any > > > > > > data that data is displayed as a preview elsewhere on the page > > > > > > instantly, just like when creating an advert with Google Adwords, the > > > > > > preview is shown. > > > > > > > I''ve been using form_remote_for and observe_form but I don''t seem to > > > > > > be having much luck at all. I am unsure how to use the controller to > > > > > > get the form fields and pass them back to a partial to be rendered? > > > > > > In this respect it''s much like a normal form, eg the title will be > > > > > params[:advert][:title] (assuming @advert is of class Advert). As > > > > > usual you can just looking at development.log to see what the > > > > > parameters look like. > > > > > > Fred > > > > > > > Here is my form: > > > > > > > <% form_remote_for @advert do |a| %> > > > > > > <label>Title:</label> <%= a.text_field :title %> > > > > > > <br /> > > > > > > <label>First Line:</label> <%= a.text_field :first_line %> > > > > > > <br /> > > > > > > <label>Second Line:</label> <%= a.text_field :second_line %> > > > > > > <br /> > > > > > > <label>Visible URL:</label> <%= a.text_field :visible_url %> > > > > > > <br /> > > > > > > <label>Destination URL:</label> <%= a.text_field :destination_url %> > > > > > > <%= submit_tag ''Submit'' %> > > > > > > <% end %> > > > > > > > Any help would be great? > > > > > > > Cheers, > > > > > > > Phil- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
phil7085 wrote:> How would I then need to tell rails to use the @advert object because > that''s the part that I have been having trouble with?Formerly, it was this: def preview @advert = Advert.new(params[:advert]) render :partial => ''advert'', :locals =>{ :@advert => @advert } end I prefer that style because it makes @advert, inside the partial, safe to test for nil. However, on our latest new project (Rails 2.2.2) either we did something else wrong, or the :@ stopped working, and we had to use this: render :partial => ''advert'', :locals =>{ :advert => @advert } Does anyone know if the :@ trick should still work? -- Phlip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 1, 8:12 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> Thanks Fred, > > How would I then need to tell rails to use the @advert object because > that''s the part that I have been having trouble with? >render :partial => ''blah'', :object => foo Fred> Phil > > On Mar 1, 7:41 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Mar 1, 7:38 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> I am simply trying to show what the user enters somewhere else on the > > > page as they type it. > > > > I did get it to work using render :text => param[:advert][:title] + > > > ''<br/>'' + param[:advert][:first_line] ...... > > > > But I think there should be a more efficient way to do it? > > > > Could I do something like this: > > > > def preview > > > @advert = Advert.new(params[:advert]) > > > render :partial => ''advert'' > > > end > > > Something like that is fine (although you''ll need to tell rails to use > > the @advert object). It''s not more efficient in terms of raw cpu > > cycles but I''m assuming that''s not what you meant (it is a lot easier > > on the eye and a better separation of presentation from your actual > > code). > > > Fred > > > > Phil > > > > On Mar 1, 7:31 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > On Mar 1, 5:10 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > > > So then do I need to use the controller to populate another @advert > > > > > object with all the params then render the partial? > > > > > Well I don''t know exactly what this controller is trying to do at all. > > > > Assuming what it''s doing is create a new object then the controller > > > > code is almost exactly the same as a regular create action, the only > > > > difference is that instead of redirecting to the show action you''re > > > > rendering a partial for the object you''ve just created. > > > > > Fred > > > > > > Cheers, > > > > > > Phil > > > > > > On Mar 1, 5:00 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > wrote: > > > > > > > On Mar 1, 1:04 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > > > > > I''ve been trying to create a simple form which when a user enters any > > > > > > > data that data is displayed as a preview elsewhere on the page > > > > > > > instantly, just like when creating an advert with Google Adwords, the > > > > > > > preview is shown. > > > > > > > > I''ve been using form_remote_for and observe_form but I don''t seem to > > > > > > > be having much luck at all. I am unsure how to use the controller to > > > > > > > get the form fields and pass them back to a partial to be rendered? > > > > > > > In this respect it''s much like a normal form, eg the title will be > > > > > > params[:advert][:title] (assuming @advert is of class Advert). As > > > > > > usual you can just looking at development.log to see what the > > > > > > parameters look like. > > > > > > > Fred > > > > > > > > Here is my form: > > > > > > > > <% form_remote_for @advert do |a| %> > > > > > > > <label>Title:</label> <%= a.text_field :title %> > > > > > > > <br /> > > > > > > > <label>First Line:</label> <%= a.text_field :first_line %> > > > > > > > <br /> > > > > > > > <label>Second Line:</label> <%= a.text_field :second_line %> > > > > > > > <br /> > > > > > > > <label>Visible URL:</label> <%= a.text_field :visible_url %> > > > > > > > <br /> > > > > > > > <label>Destination URL:</label> <%= a.text_field :destination_url %> > > > > > > > <%= submit_tag ''Submit'' %> > > > > > > > <% end %> > > > > > > > > Any help would be great? > > > > > > > > Cheers, > > > > > > > > Phil- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> render :partial => ''blah'', :object => fooTo save me from Googling for "object", what does that look like inside the partial? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 1, 8:42 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Frederick Cheung wrote: > > render :partial => ''blah'', :object => foo > > To save me from Googling for "object", what does that look like inside the partial?the object specified in that way is assigned to a local variable called object and to a local variable called after the partial (ie the same thing that happens when you do :collection => foos) (or using the name specified in the :as option) Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, I will give this a try, although as a newbie this talk of :locals, :object, etc has slightly gone over my head. I''m sure i''ll get it. Phil On Mar 1, 8:37 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> phil7085 wrote: > > How would I then need to tell rails to use the @advert object because > > that''s the part that I have been having trouble with? > > Formerly, it was this: > > def preview > @advert = Advert.new(params[:advert]) > render :partial => ''advert'', :locals =>{ :@advert => @advert } > end > > I prefer that style because it makes @advert, inside the partial, safe to test > for nil. However, on our latest new project (Rails 2.2.2) either we did > something else wrong, or the :@ stopped working, and we had to use this: > > render :partial => ''advert'', :locals =>{ :advert => @advert } > > Does anyone know if the :@ trick should still work? > > -- > Phlip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi guys, I''ve tried both of those options and can''t get it to work, I think it''s the way I am trying to retrieve the values in the partial. In the development.log I have this error: undefined method `title'' for #<HashWithIndifferentAccess:0x1f7f930> In my controller I have this: render :partial => ''advert'', :object => @advert And in my partial I have tried both if these: <%= advert.title %> <%= @advert.title %> No luck. Any suggestions? Phil On Mar 1, 8:59 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> Thanks, > > I will give this a try, although as a newbie this talk > of :locals, :object, etc has slightly gone over my head. I''m sure i''ll > get it. > > Phil > > On Mar 1, 8:37 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > phil7085 wrote: > > > How would I then need to tell rails to use the @advert object because > > > that''s the part that I have been having trouble with? > > > Formerly, it was this: > > > def preview > > @advert = Advert.new(params[:advert]) > > render :partial => ''advert'', :locals =>{ :@advert => @advert } > > end > > > I prefer that style because it makes @advert, inside the partial, safe to test > > for nil. However, on our latest new project (Rails 2.2.2) either we did > > something else wrong, or the :@ stopped working, and we had to use this: > > > render :partial => ''advert'', :locals =>{ :advert => @advert } > > > Does anyone know if the :@ trick should still work? > > > -- > > Phlip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok I''ve got it to work by using this in my partial: <%= @advert[:title] %> Can you tell me why I have to reference like this? Phil On Mar 2, 8:22 am, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> Hi guys, > > I''ve tried both of those options and can''t get it to work, I think > it''s the way I am trying to retrieve the values in the partial. > > In the development.log I have this error: undefined method `title'' for > #<HashWithIndifferentAccess:0x1f7f930> > > In my controller I have this: > > render :partial => ''advert'', :object => @advert > > And in my partial I have tried both if these: > > <%= advert.title %> > <%= @advert.title %> > > No luck. > > Any suggestions? > > Phil > > On Mar 1, 8:59 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > Thanks, > > > I will give this a try, although as a newbie this talk > > of :locals, :object, etc has slightly gone over my head. I''m sure i''ll > > get it. > > > Phil > > > On Mar 1, 8:37 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > phil7085 wrote: > > > > How would I then need to tell rails to use the @advert object because > > > > that''s the part that I have been having trouble with? > > > > Formerly, it was this: > > > > def preview > > > @advert = Advert.new(params[:advert]) > > > render :partial => ''advert'', :locals =>{ :@advert => @advert } > > > end > > > > I prefer that style because it makes @advert, inside the partial, safe to test > > > for nil. However, on our latest new project (Rails 2.2.2) either we did > > > something else wrong, or the :@ stopped working, and we had to use this: > > > > render :partial => ''advert'', :locals =>{ :advert => @advert } > > > > Does anyone know if the :@ trick should still work? > > > > -- > > > Phlip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 2, 8:39 am, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> Ok I''ve got it to work by using this in my partial: > > <%= @advert[:title] %> > > Can you tell me why I have to reference like this? >The errors you mentionned imply that @advert isn''t actually an instance of the Advert class. Fred> Phil > > On Mar 2, 8:22 am, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > Hi guys, > > > I''ve tried both of those options and can''t get it to work, I think > > it''s the way I am trying to retrieve the values in the partial. > > > In the development.log I have this error: undefined method `title'' for > > #<HashWithIndifferentAccess:0x1f7f930> > > > In my controller I have this: > > > render :partial => ''advert'', :object => @advert > > > And in my partial I have tried both if these: > > > <%= advert.title %> > > <%= @advert.title %> > > > No luck. > > > Any suggestions? > > > Phil > > > On Mar 1, 8:59 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > Thanks, > > > > I will give this a try, although as a newbie this talk > > > of :locals, :object, etc has slightly gone over my head. I''m sure i''ll > > > get it. > > > > Phil > > > > On Mar 1, 8:37 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > phil7085 wrote: > > > > > How would I then need to tell rails to use the @advert object because > > > > > that''s the part that I have been having trouble with? > > > > > Formerly, it was this: > > > > > def preview > > > > @advert = Advert.new(params[:advert]) > > > > render :partial => ''advert'', :locals =>{ :@advert => @advert } > > > > end > > > > > I prefer that style because it makes @advert, inside the partial, safe to test > > > > for nil. However, on our latest new project (Rails 2.2.2) either we did > > > > something else wrong, or the :@ stopped working, and we had to use this: > > > > > render :partial => ''advert'', :locals =>{ :advert => @advert } > > > > > Does anyone know if the :@ trick should still work? > > > > > -- > > > > Phlip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok Fred, I think I understand, I''ve now changed the controller to look like this: def preview @advert = Advert.new(params[:advert]) render :partial => ''advert'', :object => @advert end Before I had: @advert = params[:advert] which I think is what you mean by it not being an instance of the class. Now in my partial I can use @advert.title and all works fine. Thanks for all your help. Phil On Mar 2, 9:13 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 2, 8:39 am, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote:> Ok I''ve got it to work by using this in my partial: > > > <%= @advert[:title] %> > > > Can you tell me why I have to reference like this? > > The errors you mentionned imply that @advert isn''t actually an > instance of the Advert class. > > Fred > > > Phil > > > On Mar 2, 8:22 am, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > Hi guys, > > > > I''ve tried both of those options and can''t get it to work, I think > > > it''s the way I am trying to retrieve the values in the partial. > > > > In the development.log I have this error: undefined method `title'' for > > > #<HashWithIndifferentAccess:0x1f7f930> > > > > In my controller I have this: > > > > render :partial => ''advert'', :object => @advert > > > > And in my partial I have tried both if these: > > > > <%= advert.title %> > > > <%= @advert.title %> > > > > No luck. > > > > Any suggestions? > > > > Phil > > > > On Mar 1, 8:59 pm, phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> wrote: > > > > > Thanks, > > > > > I will give this a try, although as a newbie this talk > > > > of :locals, :object, etc has slightly gone over my head. I''m sure i''ll > > > > get it. > > > > > Phil > > > > > On Mar 1, 8:37 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > phil7085 wrote: > > > > > > How would I then need to tell rails to use the @advert object because > > > > > > that''s the part that I have been having trouble with? > > > > > > Formerly, it was this: > > > > > > def preview > > > > > @advert = Advert.new(params[:advert]) > > > > > render :partial => ''advert'', :locals =>{ :@advert => @advert } > > > > > end > > > > > > I prefer that style because it makes @advert, inside the partial, safe to test > > > > > for nil. However, on our latest new project (Rails 2.2.2) either we did > > > > > something else wrong, or the :@ stopped working, and we had to use this: > > > > > > render :partial => ''advert'', :locals =>{ :advert => @advert } > > > > > > Does anyone know if the :@ trick should still work? > > > > > > -- > > > > > Phlip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---