Hello, I started to use rails few weeks ago, and I have got basic question about it. 1. There is a way to keep my form filled, after submit it (for example if I get errors) ? 2. I would like to create a ''tree'' with my datas like ''pages'' for example : a page has one children and belongs to a page. I added has_one and belongs_to to the model but it doesn''t work. 3. My last question is about the models test. For example : validates_presence_of :name, :price, :description, :message => ''required'' I would like to match this message in my controller to display it in a flash after... Can you help me for these points please ! Cheers, Vincent -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 1 Sep 2008, at 13:16, Vincent Pérès wrote:> > Hello, > > I started to use rails few weeks ago, and I have got basic question > about it. > > 1. There is a way to keep my form filled, after submit it (for example > if I get errors) ? >typically this is done by rendering the form. This is the common if @foo.save redirect_to ... else render ... end pattern which you should be able to find many examples off> 2. I would like to create a ''tree'' with my datas like ''pages'' for > example : a page has one children and belongs to a page. I added > has_one > and belongs_to to the model but it doesn''t work. >''it doesn''t work'' is too vague to be able to offer any real advice. You''ll need to play with the class_name and foreign_key options (or possible have a look at acts_as_tree)> 3. My last question is about the models test. For example : > validates_presence_of :name, :price, :description, :message => > ''required'' > I would like to match this message in my controller to display it in a > flash after...Assuming your record is @record then @record.errors contains information about the failed validations (eg @record.errors.full_messages. It can also do stuff like only give you errors on certains fields etc...) Fred> > > Can you help me for these points please ! > > Cheers, > Vincent > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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. If you assign the instance variable of your model to the view and use a form helper to build your forms, Rails will automatically assign a value if it is present in the instance object''s hash: actionpack-2.1.0/lib/action_view/helpers/form_helper.rb, line 568: (...) => 568 content_tag("textarea", html_escape(options.delete(''value'') || value_before_type_cast(object)), options) (...) The call to content tag tries to extract the value from the object or deletes the tag if it is not present. Where object is the object (model''s instance) that has been passed to the form_for helper method. So, just follow Frederick''s advice and you should be good to go :) Marcelo. On Mon, Sep 1, 2008 at 9:22 AM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8@public.gmane.orgm> wrote:> > > On 1 Sep 2008, at 13:16, Vincent Pérès wrote: > > > > > Hello, > > > > I started to use rails few weeks ago, and I have got basic question > > about it. > > > > 1. There is a way to keep my form filled, after submit it (for example > > if I get errors) ? > > > typically this is done by rendering the form. This is the common > if @foo.save > redirect_to ... > else > render ... > end > > pattern which you should be able to find many examples off > > > 2. I would like to create a ''tree'' with my datas like ''pages'' for > > example : a page has one children and belongs to a page. I added > > has_one > > and belongs_to to the model but it doesn''t work. > > > ''it doesn''t work'' is too vague to be able to offer any real advice. > You''ll need to play with the class_name and foreign_key options (or > possible have a look at acts_as_tree) > > > > 3. My last question is about the models test. For example : > > validates_presence_of :name, :price, :description, :message => > > ''required'' > > I would like to match this message in my controller to display it in a > > flash after... > > Assuming your record is @record then @record.errors contains > information about the failed validations (eg > @record.errors.full_messages. It can also do stuff like only give you > errors on certains fields etc...) > > Fred > > > > > > Can you help me for these points please ! > > > > Cheers, > > Vincent > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello, Thanks for your quick answers ! 1. I gave @record to my form_for and it was filled automatically. 2. I will play again with belongs_to, has_one... I think it is basic configuration (page has a parent page id on each record) 3. Perfect ! I found it thanks to your answer : http://api.rubyonrails.com/classes/ActiveResource/Errors.html Cheers, Vincent -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---