Hi, I really want to know if it is possible to assign counter to the .rhtml page so that if counter=1, when the submit button is clicked, I will do the save/create action. If counter >= 2, when the submit button is clicked, I will do the update action. Thanks, user splash -- 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 -~----------~----~----~----~------~----~------~--~---
You could accomplish this with the use of sessions. I''m really still new to RoR. But basically with sessions enabled you can add code to your page controller like: def find_count session[:count] ||= 0 // Looks to see if session[:count] has been initialized, if not it will in this case set it to a value of 0. session[:count += 1 // increment by 1. First visit will be initialized to 1. Successive visits will increment as stated earlier, by 1. end then in the view code do something a control structure check like <% if session[:count] == 1 %> <% form_for :model, :url => { :action => :save } do |form| %> <%= render :partial => ''form'' %> <%= submit_tag "Save" %> <% end %> <% elsif session[:count] > 1 %> <% form_for :model, :url => { :action => :edit } do |form| %> <%= render :partial => ''form'' %> <%= submit_tag "Edit" %> <% end %> <% end %> Where the above render code will look for a file called _form.rhtml in the same folder and render the contents of that file, in this case it should contain the fields for your model. On Jan 10, 6:09 pm, user splash <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > I really want to know if it is possible to assign counter to the .rhtml > page so that if counter=1, when the submit button is clicked, I will do > the save/create action. If counter >= 2, when the submit button is > clicked, I will do the update action. > > Thanks, > user splash > -- > 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 -~----------~----~----~----~------~----~------~--~---
Neon wrote:> You could accomplish this with the use of sessions. I''m really still > new to RoR. But basically with sessions enabled you can add code to > your page controller like: > > def find_count > session[:count] ||= 0 // Looks to see if session[:count] has been > initialized, if not it will in this case set it to a value of 0. > session[:count += 1 // increment by 1. First visit will be > initialized to 1. Successive visits will increment as stated earlier, > by 1. > end > > then in the view code do something a control structure check like > > <% if session[:count] == 1 %> > <% form_for :model, :url => { :action => :save } do |form| %> > <%= render :partial => ''form'' %> > <%= submit_tag "Save" %> > <% end %> > <% elsif session[:count] > 1 %> > <% form_for :model, :url => { :action => :edit } do |form| %> > <%= render :partial => ''form'' %> > <%= submit_tag "Edit" %> > <% end %> > <% end %> > > Where the above render code will look for a file called _form.rhtml in > the same folder and render the contents of that file, in this case it > should contain the fields for your model. > On Jan 10, 6:09 pm, user splash <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Hi, The above method allows me to save the data when i first time i enter the page allows me to edit the subsequent time i enter that page. But what should i do to enable the user to update that data that was saved previously ? I thought of using the find current id to edit the data. But it will not be practical as the current id of the data might not be that particular i want to edit.Can someone tell me what should i do? Thanks, user splash -- 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 -~----------~----~----~----~------~----~------~--~---
fries 88 wrote:> Neon wrote: >> You could accomplish this with the use of sessions. I''m really still >> new to RoR. But basically with sessions enabled you can add code to >> your page controller like: >> >> def find_count >> session[:count] ||= 0 // Looks to see if session[:count] has been >> initialized, if not it will in this case set it to a value of 0. >> session[:count += 1 // increment by 1. First visit will be >> initialized to 1. Successive visits will increment as stated earlier, >> by 1. >> end >> >> then in the view code do something a control structure check like >> >> <% if session[:count] == 1 %> >> <% form_for :model, :url => { :action => :save } do |form| %> >> <%= render :partial => ''form'' %> >> <%= submit_tag "Save" %> >> <% end %> >> <% elsif session[:count] > 1 %> >> <% form_for :model, :url => { :action => :edit } do |form| %> >> <%= render :partial => ''form'' %> >> <%= submit_tag "Edit" %> >> <% end %> >> <% end %> >> >> Where the above render code will look for a file called _form.rhtml in >> the same folder and render the contents of that file, in this case it >> should contain the fields for your model. >> On Jan 10, 6:09 pm, user splash <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > > > Hi, > The above method allows me to save the data when i first time i enter > the page allows me to edit the subsequent time i enter that page. But > what should i do to enable the user to update that data that was saved > previously ? I thought of using the find current id to edit the data. > But it will not be practical as the current id of the data might not be > that particular i want to edit.Can someone tell me what should i do? > > > Thanks, > user splashHi, Adding on to the previous posting''s question, does anyone also know how to end the session? Like when ever I enter the main page a new session is created and when i click a button/link, the session will be ended. Thanks fries 88 -- 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 -~----------~----~----~----~------~----~------~--~---