Hi, Can someone tell me why doesnt this work? I have two links the action of both links are the same. They post the data from the form and suppose to redirect to two different pages respectively if i click any one of those links. The error I got is TEMPLATE IS MISSING. I didnt create that template because this method is suppose to redirect to another page. if @user.save if params[:commit] == "Previous" redirect to some page elsif params[:commit] == "Next" redirect to some page end else render the page end -- 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 -~----------~----~----~----~------~----~------~--~---
The problem is that redirect does not return, so it is falling through the bottom of the method. Try this: if @user.save if params[:commit] == "Previous" return redirect to some page elsif params[:commit] == "Next" return redirect to some page end else render the page end -Bill user splash wrote:> Hi, > Can someone tell me why doesnt this work? I have two links the action of > both links are the same. They post the data from the form and suppose to > redirect to two different pages respectively if i click any one of those > links. The error I got is TEMPLATE IS MISSING. I didnt create that > template because this method is suppose to redirect to another page. > > if @user.save > if params[:commit] == "Previous" > redirect to some page > > elsif params[:commit] == "Next" > redirect to some page > end > else > render the page > end >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
William Pratt wrote:> The problem is that redirect does not return, so it is falling through > the bottom of the method. Try this: > > if @user.save > if params[:commit] == "Previous" > return redirect to some page > > elsif params[:commit] == "Next" > return redirect to some page > end > else > render the page > end > > -Bill > Sincerely, > > William PrattHi, I''ve tried the return redirect to some page but the same TEMLPATE MISSING error is being shown. This is what I did: if user.save if params[:commit] == ''Previous return redirect_to :action => ''previous_page'' elsif params[:commit] == ''Next'' return redirect_to :action => next_page'' end else render :action=> ''current_page'' end Please correct me if I am wrong Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
Show us your form code please. On Jan 15, 2008 12:22 PM, user splash <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > Can someone tell me why doesnt this work? I have two links the action of > both links are the same. They post the data from the form and suppose to > redirect to two different pages respectively if i click any one of those > links. The error I got is TEMPLATE IS MISSING. I didnt create that > template because this method is suppose to redirect to another page. > > if @user.save > if params[:commit] == "Previous" > redirect to some page > > elsif params[:commit] == "Next" > redirect to some page > end > else > render the page > end > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I thought redirect_to DID do a return, in fact I''m sure of it. Try putting a redirect_to(:action => "index") and then a puts directly after it. On Jan 15, 2008 12:49 PM, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> > The problem is that redirect does not return, so it is falling through > the bottom of the method. Try this: > > if @user.save > if params[:commit] == "Previous" > return redirect to some page > > elsif params[:commit] == "Next" > return redirect to some page > end > else > render the page > end > > -Bill > > user splash wrote: > > Hi, > > Can someone tell me why doesnt this work? I have two links the action of > > both links are the same. They post the data from the form and suppose to > > redirect to two different pages respectively if i click any one of those > > links. The error I got is TEMPLATE IS MISSING. I didnt create that > > template because this method is suppose to redirect to another page. > > > > if @user.save > > if params[:commit] == "Previous" > > redirect to some page > > > > elsif params[:commit] == "Next" > > redirect to some page > > end > > else > > render the page > > end > > > > -- > Sincerely, > > William Pratt > > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Can you show us your form code and the exact error please? On Jan 15, 2008 12:59 PM, user splash <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > William Pratt wrote: > > The problem is that redirect does not return, so it is falling through > > the bottom of the method. Try this: > > > > if @user.save > > if params[:commit] == "Previous" > > return redirect to some page > > > > elsif params[:commit] == "Next" > > return redirect to some page > > end > > else > > render the page > > end > > > > -Bill > > Sincerely, > > > > William Pratt > > > Hi, > I''ve tried the return redirect to some page but the same TEMLPATE > MISSING error is being shown. > > This is what I did: > > if user.save > if params[:commit] == ''Previous > return redirect_to :action => ''previous_page'' > > elsif params[:commit] == ''Next'' > return redirect_to :action => next_page'' > end > else > render :action=> ''current_page'' > end > > > Please correct me if I am wrong > > Thanks > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> Show us your form code please. > On Jan 15, 2008 12:22 PM, user splash <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >> redirect to some page >> > >>Hi, This is my form, <% form_for :user, :url => { :action => :save_user}, :html => { :id => "user" } do |n| %> <label> Username:</label> <%= n.text_field :username %> <label> Password:</label> <%= n.text_field :password %> <%= link_to_function ''Previous'', "$(''user'').submit()" -%> <%= link_to_function ''Next'', "$(''user'').submit()" -%> Both links save user. And are suppose to redirect the user to previous_page and next_page respectively. I understand button is a better and a more "right" way. But is there a easier way to post using links? Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
Instead of the <%= link_to_function %>, use <%= submit_tag "Previous" %> <%= submit_tag "Next" %> On Jan 15, 2008 1:21 PM, user splash <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Ryan Bigg wrote: > > Show us your form code please. > > On Jan 15, 2008 12:22 PM, user splash <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > >> redirect to some page > >> > > >> > > > > Hi, > This is my form, > > <% form_for :user, :url => { :action => :save_user}, :html => { :id => > "user" } do |n| %> > <label> Username:</label> > <%= n.text_field :username %> > > <label> Password:</label> > <%= n.text_field :password %> > > <%= link_to_function ''Previous'', "$(''user'').submit()" -%> > <%= link_to_function ''Next'', "$(''user'').submit()" -%> > > > Both links save user. And are suppose to redirect the user to > previous_page and next_page respectively. I understand button is a > better and a more "right" way. But is there a easier way to post using > links? > > Thanks > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> Instead of the <%= link_to_function %>, use > > <%= submit_tag "Previous" %> > <%= submit_tag "Next" %> > >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > -- > Ryan Bigg > http://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.Hi, Thanks. I have tried the above submit_tag and it works. But can anyone tell me if there is a way to make link work like this submit_tag ? Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
user splash wrote:> Ryan Bigg wrote: >> Instead of the <%= link_to_function %>, use >> >> <%= submit_tag "Previous" %> >> <%= submit_tag "Next" %> >> >> -- >> Ryan Bigg >> http://www.frozenplague.net >> Feel free to add me to MSN and/or GTalk as this email. > > Hi, > Thanks. I have tried the above submit_tag and it works. But can anyone > tell me if there is a way to make link work like this submit_tag ? > > ThanksHi, Say if i create a link using: <%= link_to ''PREVIOUS'', {:controller => ''create_user, :action => "save_user", :method => :post} %> It does a post but it doesnt get the vaules from the fields and post them. It posts empty fields. Can someone help me to resolve this? Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
Use CSS to style the submit_tag how you want it. On Jan 15, 2008 2:41 PM, user splash <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > user splash wrote: > > Ryan Bigg wrote: > >> Instead of the <%= link_to_function %>, use > >> > >> <%= submit_tag "Previous" %> > >> <%= submit_tag "Next" %> > >> > >> -- > >> Ryan Bigg > >> http://www.frozenplague.net > >> Feel free to add me to MSN and/or GTalk as this email. > > > > Hi, > > Thanks. I have tried the above submit_tag and it works. But can anyone > > tell me if there is a way to make link work like this submit_tag ? > > > > Thanks > > Hi, > Say if i create a link using: > > <%= link_to ''PREVIOUS'', {:controller => ''create_user, > :action => "save_user", :method => :post} %> > > It does a post but it doesnt get the vaules from the fields and post > them. It posts empty fields. > > Can someone help me to resolve this? > > Thanks > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 Jan 14, 2008, at 10:11 PM, user splash wrote:>> >> Hi, >> Thanks. I have tried the above submit_tag and it works. But can >> anyone >> tell me if there is a way to make link work like this submit_tag ? >> >> Thanks > > Hi, > Say if i create a link using: > > <%= link_to ''PREVIOUS'', {:controller => ''create_user, > :action => "save_user", :method => :post} %> > > It does a post but it doesnt get the vaules from the fields and post > them. It posts empty fields. > > Can someone help me to resolve this? >I use a method similiar to your first approach: I have a javascript function which submits the form via AJAX. You can do it various ways, but here is the most straight-forward if you don''t need to do anything with the form values before sending them to the server: function submit_task() { clear_messages(); var f = $(''submit_task_form''); var ok = form_check_required_fields(f); if (!ok) { alert(''Required information missing.''); return false; } else { form_strip(f); new Ajax.Request(''/wgg/submit_task'', { method: ''post'', parameters: f.serialize(), onFailure: function(){ alert(''Unable to submit task.'') }, onException: function(o,e) { alert(e) } }); } } In this function, I have some utility methods that I use (clear_messages, form_check_required_fields, and form_strip), so don''t get tripped up by those. The most important part for your case is the new Ajax.Request block. Notice that the method is post and the parameters are f.serialize, so all of the form fields will be serialized and passed to the server just like if you used the submit_tag. Depending on how you link to this function, you might also need to "return false" so the form is not submitted twice. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> function submit_task() > { > clear_messages(); > > var f = $(''submit_task_form''); > var ok = form_check_required_fields(f); > if (!ok) > { > alert(''Required information missing.''); > return false; > } > else > { > form_strip(f); > new Ajax.Request(''/wgg/submit_task'', { > method: ''post'', > parameters: f.serialize(), > onFailure: function(){ alert(''Unable to submit task.'') }, > onException: function(o,e) { alert(e) } > }); > } > } >Hi, Where do I put this function? In rhtml? I tried that and it show Unknown action No action responded to submit_task() error. I place the whole block of code in <script></script> and call the function like this, <%= link_to ''PREVIOUS'', onclick="submit_task()" %> Did I do something wrong? Please explain. Thanks -- 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 Jan 15, 2008, at 7:34 PM, user splash wrote:> > Hi, > Where do I put this function? In rhtml? I tried that and it show > Unknown > action > No action responded to submit_task() error. I place the whole block of > code in <script></script> and call the function like this, <%= link_to > ''PREVIOUS'', onclick="submit_task()" %> Did I do something wrong? > Please > explain. >This is a javascript function that would go in a js file in public/ javascripts. For testing purposes, you could put it in application.js, but I wouldn''t leave it there long term. To call it, you''d do something like what you have <%= link_to_function ''Previous'', ''submit_task();'' %> See if that gets you any further. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe wrote:> On Jan 15, 2008, at 7:34 PM, user splash wrote: >> > This is a javascript function that would go in a js file in public/ > javascripts. For testing purposes, you could put it in > application.js, but I wouldn''t leave it there long term. To call it, > you''d do something like what you have > > <%= link_to_function ''Previous'', ''submit_task();'' %> > > See if that gets you any further. > > Peace, > PhillipHi, I''ve tried the codes. But I didn''t get what I expected, to submit the form and get redirected to the next/previous page. Where did I go wrong or maybe I missed some steps or maybe I did not totally understand the function ''submit_task''. Please explain. function submit_task() { clear_messages(); var f = $(''submit_task_form''); ///// WHAT DOES THIS DO? DO I HAVE TO CHANGE THIS? var ok = form_check_required_fields(f); if (!ok) { alert(''Required information missing.''); return false; } else { form_strip(f); new Ajax.Request(''/wgg/submit_task'', { //////WHAT DOES THIS DO? DO I HAVE TO CHANGE THIS? method: ''post'', parameters: f.serialize(), onFailure: function(){ alert(''Unable to submit task.'') }, onException: function(o,e) { alert(e) } }); return false; ////////IS IT RIGHT TO RETURN FALSE HERE TO PREVENT THE FORM FROM BEING SUBMITED TWICE? } } Thanks -- 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 Jan 15, 2008, at 8:53 PM, user splash wrote:> > Hi, > I''ve tried the codes. But I didn''t get what I expected, to submit the > form and get redirected to the next/previous page. Where did I go > wrong > or maybe I missed some steps or maybe I did not totally understand the > function ''submit_task''. Please explain. > > > function submit_task() > { > clear_messages(); > > var f = $(''submit_task_form''); ///// WHAT DOES THIS DO? DO I > HAVE TO > CHANGE THIS? > > var ok = form_check_required_fields(f); > if (!ok) > { > alert(''Required information missing.''); > return false; > } > else > { > form_strip(f); > new Ajax.Request(''/wgg/submit_task'', { //////WHAT DOES THIS > DO? DO > I HAVE TO CHANGE THIS? > > method: ''post'', > parameters: f.serialize(), > onFailure: function(){ alert(''Unable to submit task.'') }, > onException: function(o,e) { alert(e) } > }); > return false; ////////IS IT RIGHT TO RETURN FALSE HERE TO > PREVENT THE > FORM FROM BEING SUBMITED TWICE? > } > } > >Hm. Please don''t take offense to this, but you might be in over your head right now. I posted that function as an example of what you *can* do. I didn''t intend for you to try to use it verbatim in your code. You were having a problem getting all of your form fields to make it across to your controller. This method was shown to give you an example of how to serialize a form. But to answer some of your questions... var f = $(''submit_task_form''); assigns the form to the local variable f. $() is a Prototype function. f will be passed to other functions to do things that I need to do. In my original message, I mentioned that there were a few functions that you didn''t need to pay attention to. /wgg/submit_task is an action in a controller in my application. You would use whatever action you post your form to. the "return false" at the end of the function is *not* sufficient to prevent double submission of the form. You would need to include "return false" in the event handler that calls the javascript function: onclick="some_function(); return false;" Let me ask you a question: have you spent much time working through any tutorials? How about the Agile Web Development with Rails book? I don''t mean to criticize you, especially for being new to RoR, but it seems to me like you have a lack of understanding of the fundamentals of Javascript and RoR. Trying to take someone else''s code, offered as an example, and just drop it into your application and hope it works is rarely going to get you the results you desire. I am pretty new to RoR. It''s been about 9 months now. I started with the above mentioned book and worked on a piddly little app, just to get my bearings. I''ve been working on some "real apps" now for a few months, and I''m learning more and more every day. While not technically mind-boggling, some of the things I''m doing are not going to make a whole lot of sense to someone who is not yet versed in the interaction between Javascript and RoR. Please, for your own good, step back from this project and think about what you are trying to accomplish. Take a little time and work through some things, step by step, until you get a feel for how it all works. You''ll save yourself a whole bunch of hair pulling. Really. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---