0

I have submit button and i want to redirect in another URL (hard coded) this URL

https://www.ccavenue.com/shopzone/cc_details.jsp

my code :

<%= form_tag @ccavanue do |f| , url => "https://www.ccavenue.com/shopzone/cc_details.jsp",       :html => :method => "put" %>
<%= hidden_field_tag :my_field, @MerchantId, :id => 'merchant_id' %>
<%= submit_tag "Click Me"  %>
<% end %>

i want to redirect another website URL with this submit button . please guided me.

Apoorv Awasthi
  • 1,397
  • 1
  • 12
  • 20
Swetz
  • 1
  • 2
  • what you write seems like you want to `post` to a url in another site. That is not a good idea, http://stackoverflow.com/questions/11423682/cross-domain-form-posting . If you want to redirect after that post, you should add the relevant code to your controller to perform a get request to that location. – xlembouras May 09 '14 at 06:52

1 Answers1

1

Change your code to following:

<%= form_for @ccavanue, url: "https://www.ccavenue.com/shopzone/cc_details.jsp" do |f| %>
   <%= f.hidden_field :my_field, @MerchantId, :id => 'merchant_id' %>
   <%= f.submit "Click Me"  %>
<% end %>

In Rails a form is designed to create or update a resource and reflects the identity of the resource in several ways:

  1. The url that the form is sent to (the form element's action attribute) should result in a request being routed to the appropriate controller action (with the appropriate :id parameter in the case of an existing resource),
  2. Input fields should be named in such a way that in the controller their values appear in the appropriate places within the params hash, and
  3. For an existing record, when the form is initially displayed, input fields corresponding to attributes of the resource should show the current values of those attributes.

In Rails this is achieved by creating form using form_for where:

If we want to create any object we use POST method within url and PUT method if we are trying to update an existing record.

Rails framework is smart enough to use POST or PUT method by itself looking at the url of the form. So in this case we need not use method parameter within form_for url.

Probably you can start with Michael Hartl's tutorial

cvibha
  • 693
  • 5
  • 9
  • I am not sure why you are using "put" method to form_for but try not to pass method parameter in form_for – cvibha May 13 '14 at 00:11
  • I am not aware about this. i am in new in ruby and i want to purchase book of Ruby on Rails for best beginning to learn . please guided me – Swetz May 13 '14 at 05:49
  • I have modified the answer with relevant guide to Ruby on Rails. Please look at the edited answer – cvibha May 14 '14 at 00:13