Dale Cunnigham
2008-Jun-03 11:31 UTC
Newbie: Corrcet use of Render :Partial for forms in CRUD?
Cna anyone point e at any rails 2.0 tutorials on simple use of partials for forms in new and update CRUD operations? Ive got the following new.html.erb and _user.html.erb partial First the contents of new.html.erb <h1>New user</h1> <%= error_messages_for :user %> <% form_for(@user) do |f| %> <%= render :partial => @user %> <p> <%= f.submit "Create" %> </p> <% end %> <%= link_to ''Back'', users_path %> ....and the form partial.... _user.html.erb <p> <b>ImageName</b><br /> <%= f.text_field :ImageName" %> </p> <p> <b>Surname</b><br /> <%= f.text_field :SurName" %> </p> <p> <b>Forename</b><br /> <%= f.text_field :ForeName" %> </p> <p> <b>Title</b><br /> <%= f.text_field :Title" %> </p> <p> <b>Room No</b><br /> <%= f.text_field :RoomNo" %> </p> <p> <b>Phone No</b><br /> <%= f.text_field :PhoneNo" %> </p> <p> <b>Position / Group</b><br /> <%= f.text_field :Position_Group" %> </p> <p> <b>Duties</b><br /> <%= f.text_field :Duties" %> </p> <p> <b>EMail</b><br /> <%= f.text_field :EMail" %> </p> -- 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 -~----------~----~----~----~------~----~------~--~---
Elizabeth Barnwell
2008-Jun-03 16:24 UTC
Re: Newbie: Corrcet use of Render :Partial for forms in CRUD?
Hi Dale, I''m new to this too... for general reference, this may be useful: http://www.yoyobrain.com/cardboxes/preview/863 there''s info on rails and a tool to help you learn rails. Best, Elizabeth On Jun 3, 6:31 am, Dale Cunnigham <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Cna anyone point e at any rails 2.0 tutorials on simple use of partials > for forms in new and update CRUD operations? > > Ive got the following new.html.erb and _user.html.erb partial > > First the contents of new.html.erb > > <h1>New user</h1> > > <%= error_messages_for :user %> > > <% form_for(@user) do |f| %> > > <%= render :partial => @user %> > > <p> > <%= f.submit "Create" %> > </p> > <% end %> > > <%= link_to ''Back'', users_path %> > > ....and the form partial.... > > _user.html.erb > > <p> > <b>ImageName</b><br /> > <%= f.text_field :ImageName" %> > </p> > > <p> > <b>Surname</b><br /> > <%= f.text_field :SurName" %> > </p> > > <p> > <b>Forename</b><br /> > <%= f.text_field :ForeName" %> > </p> > > <p> > <b>Title</b><br /> > <%= f.text_field :Title" %> > </p> > > <p> > <b>Room No</b><br /> > <%= f.text_field :RoomNo" %> > </p> > > <p> > <b>Phone No</b><br /> > <%= f.text_field :PhoneNo" %> > </p> > > <p> > <b>Position / Group</b><br /> > <%= f.text_field :Position_Group" %> > </p> > > <p> > <b>Duties</b><br /> > <%= f.text_field :Duties" %> > </p> > > <p> > <b>EMail</b><br /> > <%= f.text_field :EMail" %> > </p> > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Ar Chron
2008-Jun-03 17:04 UTC
Re: Newbie: Corrcet use of Render :Partial for forms in CRUD
Dale Cunnigham wrote:> Cna anyone point e at any rails 2.0 tutorials on simple use of partials > for forms in new and update CRUD operations?At a basic level, you can think of a partial as a Lego building block... from which you create your web form. You can have any number of partials, each of which presents a different piece of your final application. I use partials for all sorts of things on a web form - menus, content, navigation links, etc. Let''s say, from your example, that you want the new action for some model to show ALL the attributes of the model, but you want the edit action to only show a subset of the model attributes. If you put the code related to the attributes common to those actions (new and edit) into a partial, the new.html.erb can show the fields it needs to show AND render the partial while the edit.html.erb would just render the partial. The value of partials really comes weighing the reusability of a chunk of code and the cost to execute that hunk of code... Would we put something into a partial that''s used only one place? Probably not. But, if your app shows, for instance, an address on multiple different forms, you can create a partial that renders an address, and all the places that need to show an address can employ that same partial. Less code for you to maintain, and an enforced consistency within your application - all addresses render the same. If it''s a duck, it should look like a duck. The next extension to that idea, at least for me, was to only render something again (invoke the partial) if it changed since the last time it was rendered. This gets into caching and cache sweepers. I put most "slow moving" data (data that changes infrequently) into a partial that I can cache - the left-nav menus available for a specific user, for instance. Unless the admin changes permissions for a user, the menu that user sees won''t change, and my app doesn''t have to regen the menus all the time (fits my "slow moving" data rule). If the list of models related to a given project (another of my models) hasn''t changed, don''t re-render the partial that creates hyperlinks to all those related models - which can be a lot of work - but show the cached version of that partial (fits my "expensive to do" rule). Divorcing that -- 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 -~----------~----~----~----~------~----~------~--~---
Ar Chron
2008-Jun-03 17:06 UTC
Re: Newbie: Corrcet use of Render :Partial for forms in CRUD
Ar Chron wrote:> Divorcing thatjust ignore that incomplete thought... :( -- 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 -~----------~----~----~----~------~----~------~--~---
Pardee, Roy
2008-Jun-03 17:43 UTC
Re: Newbie: Corrcet use of Render :Partial for forms in CRUD?
So is this not working for you? The only thing I might want to add is to pass the form helper object ''f'' to the partial in the :locals hash. Not sure if that''s necessary... -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Dale Cunnigham Sent: Tuesday, June 03, 2008 4:31 AM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Newbie: Corrcet use of Render :Partial for forms in CRUD? Cna anyone point e at any rails 2.0 tutorials on simple use of partials for forms in new and update CRUD operations? Ive got the following new.html.erb and _user.html.erb partial First the contents of new.html.erb <h1>New user</h1> <%= error_messages_for :user %> <% form_for(@user) do |f| %> <%= render :partial => @user %> <p> <%= f.submit "Create" %> </p> <% end %> <%= link_to ''Back'', users_path %> ....and the form partial.... _user.html.erb <p> <b>ImageName</b><br /> <%= f.text_field :ImageName" %> </p> <p> <b>Surname</b><br /> <%= f.text_field :SurName" %> </p> <p> <b>Forename</b><br /> <%= f.text_field :ForeName" %> </p> <p> <b>Title</b><br /> <%= f.text_field :Title" %> </p> <p> <b>Room No</b><br /> <%= f.text_field :RoomNo" %> </p> <p> <b>Phone No</b><br /> <%= f.text_field :PhoneNo" %> </p> <p> <b>Position / Group</b><br /> <%= f.text_field :Position_Group" %> </p> <p> <b>Duties</b><br /> <%= f.text_field :Duties" %> </p> <p> <b>EMail</b><br /> <%= f.text_field :EMail" %> </p> -- 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 -~----------~----~----~----~------~----~------~--~---