Take the 2-minute tour ×

I'm trying to save records in a database. Many of the column values will be taken from a http request to an api.

I have a text field and some check boxes along with the session_id in the form which will be persisted. this is posted from another controller (form_tag('results#store'))to an action called store in the results controller.

Store action:

def store

  query = query_preprocesser(params[:query]) # this is in a helper

  ## example of resArray ##
  #resArray = [[{:engine => "bing, :results => [{:Description => "abc", :Title => "def"}, {:Description => "ghi", :Title => "jkl"}]}, {etc},{etc} ],[{:eng...}]]

  resArray = getResults(query) # Also a helper method returning an array of up to 3 arrays
  resArray.each do |engine|
  db_name = engine[:engine]
      engine[:results].each do |set|

        res = Result.new(
        :session_id => params[:session_id], 
        :db_name => db_name,
        :query => query,
        :rank => set[:Rank],
        :description => set[:Description],
        :title => set[:Title],
        :url => set[:Url] )

res.each do |res|
#Result.new(:session_id => params[:session_id], :db_name => "Bing", :query => "Whats the story", :query_rank => 1, :title => "The Title", :description => "descript", :url => "www.google.ie",:query_number => 1)

respond_to do |format|
      format.html { redirect_to pages_path }
      format.json { head :no_content }

My routes are resources :results

Server logs:

[2012-07-10 23:30:48] INFO  WEBrick 1.3.1
[2012-07-10 23:30:48] INFO  ruby 1.9.3 (2012-04-20) [x86_64-linux]
[2012-07-10 23:30:48] INFO  WEBrick::HTTPServer#start: pid=15584 port=3000

Started POST "/results" for at 2012-07-10 23:31:36 +0100
Connecting to database specified by database.yml
Processing by ResultsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"/nTJOF5Ab+XnL+jxRBHnTJz45YRVmgbf55bmn5/iz8E=", "query"=>"search term", "button"=>"", "searchType"=>"Seperate", "bing"=>"1", "session_id"=>"e08c13a99f21a91520fcc393e0860c94"}
(0.2ms)  begin transaction
(0.2ms)  rollback transaction
Rendered results/_form.html.erb (13.9ms)
Rendered results/new.html.erb within layouts/application (23.6ms)
Completed 200 OK in 213ms (Views: 78.4ms | ActiveRecord: 2.9ms)


<%= form_tag('results#store') do %>

Rake routes:

       store POST   /pages(.:format)             results#store
      results GET    /results(.:format)           results#index
              POST   /results(.:format)           results#create
   new_result GET    /results/new(.:format)       results#new
  edit_result GET    /results/:id/edit(.:format)  results#edit
       result GET    /results/:id(.:format)       results#show
              PUT    /results/:id(.:format)       results#update
              DELETE /results/:id(.:format)       results#destroy
        store POST   /pages(.:format)             results#store
        pages GET    /pages(.:format)             pages#index

I keep getting redirected to the new action in Results controller. The helper methods aren't even being executed. I'm a past master at over complicating things, can anyone help unravel this for me?

share|improve this question
Describe a little more how you get here. What url do you visit first? Post the server logs for the entire journey (start url, form submission, redirect to new). –  Dean Brundage Jul 10 '12 at 22:21
I start from the pages#index, that's where the form is. –  Nultyi Jul 10 '12 at 22:40
I'm being redirected from the create action because non of the parameters are reaching the action and they are validated in the model. I still can't understand why the form is being posted to the create action when I have specified the store action... –  Nultyi Jul 10 '12 at 23:35
add comment

1 Answer

up vote 0 down vote accepted

Do you have a route set up for the store action? If you do then you should use the url helper for it in your form tag:

form_tag( results_store_url )
share|improve this answer
Top man Dean :) Its works with store_url. I've been tinkering with the routes for the past hour+ and it's all come together! I clearly need to look harder at routing. :| What I don't understand is the HTML says http://localhost:3000/pages for action with store_url - guess I'll find out why when I read more about routes. Thanks again Dean! –  Nultyi Jul 11 '12 at 0:05
add comment

Your Answer


