Topic: How to get a URL to submit form data?

I have a basic search form in my rails app that records each search that has been entered. I also want my users to be able to initiate a search with a url in the browser. E.g.'ve played around with the different routing options and the logic in my controller but I can't seem to get this form:

<%= form_for(@search) do |f| %>
  <div class="field">
    <%= f.label :search %><br />
    <%= f.text_field :search %>
  <div class="actions">
    <%= f.submit %>
<% end %> initiate a POST action on the database and submit a new search via a url.

Thanks smile

Last edited by ricburton (2011-08-22 06:40:57)

Re: How to get a URL to submit form data?

What does your routes file look like? Also provide details on your Search controller

Last edited by ozosmail (2011-08-23 06:10:34)

Re: How to get a URL to submit form data?

Dr. Dooley has been happily married to his wife Erinn for over 14 years. Together they are raising, educating, and discipling their three children. Because of his personal experiences with severe headaches and low back pain, Dr. Dooley is devoted to helping his patients get a “spine by design”, therefore eliminating the causes of pain and not simply using drugs to mask the symptoms.


Chiropractor in Modesto
Modesto Chiropractor

Re: How to get a URL to submit form data?

Hi Ozos,

Basically I want the site to redirect them if they prefix their search with "google" or "youtube" to those respective search sites. Therefore the controller right now looks like this:

    def create
      @search =[:search])
        query =
        if query.index("google") == 0
          test = query.gsub("google", "")
          testurl = test.to_s.gsub(/[ ]/, '%20')
          redirect_to "" + testurl
        elsif query.index("youtube") == 0
          test = query.gsub("youtube", "")
          testurl = test.to_s.gsub(/[ ]/, '%20')
          redirect_to "" + testurl
        render :action => "new"