Problems with params[:commit]

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

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:

      elsif params[:commit] == "Next"
            redirect to some page
      end
  else
    render the page
end


Sincerely,

William P.

William P. 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 P.

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

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 P. [email protected] wrote:

     end

redirect to two different pages respectively if i click any one of those
else


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Show us your form code please.
On Jan 15, 2008 12:22 PM, user splash [email protected]
wrote:

       redirect to some page


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Can you show us your form code and the exact error please?

On Jan 15, 2008 12:59 PM, user splash [email protected]
wrote:

        return redirect to some page
       elsif params[:commit] == 'Next'


Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Instead of the <%= link_to_function %>, use

<%= submit_tag “Previous” %>
<%= submit_tag “Next” %>

On Jan 15, 2008 1:21 PM, user splash [email protected]
wrote:

<%= n.text_field :password %>
Thanks

Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Ryan B. wrote:

Instead of the <%= link_to_function %>, use

<%= submit_tag “Previous” %>
<%= submit_tag “Next” %>


Posted via http://www.ruby-forum.com/.


Ryan B.
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

Ryan B. wrote:

Show us your form code please.
On Jan 15, 2008 12:22 PM, user splash [email protected]
wrote:

       redirect to some page

Hi,
This is my form,

<% form_for :user, :url => { :action => :save_user}, :html => { :id =>
“user” } do |n| %>
Username:
<%= n.text_field :username %>

Password:
<%= 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

Use CSS to style the submit_tag how you want it.

On Jan 15, 2008 2:41 PM, user splash [email protected]
wrote:

http://www.frozenplague.net

Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

user splash wrote:

Ryan B. wrote:

Instead of the <%= link_to_function %>, use

<%= submit_tag “Previous” %>
<%= submit_tag “Next” %>


Ryan B.
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

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 and call the function like this, <%= link_to
‘PREVIOUS’, onclick=“submit_task()” %> Did I do something wrong? Please
explain.

Thanks

On Jan 14, 2008, at 10:11 PM, user splash wrote:

<%= 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

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,
Phillip

Phillip K. 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,
Phillip

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?
}
}

Thanks

On Jan 15, 2008, at 8:53 PM, user splash wrote:

{
return false;
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 D. 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