0

我正在尝试将记录保存在数据库中。许多列值将从 http 请求获取到 api。

我有一个文本字段和一些复选框以及将保留的表单中的 session_id。这从另一个控制器 ( ) 发布到结果控制器中form_tag('results#store')调用的操作。store

存储操作:

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.save!
   end
  end

res.each do |res|
    res.save
end
#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 }
    end
end

我的路线是resources :results

服务器日志:

[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 127.0.0.1 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 %>

耙路线:

       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

我不断被重定向到结果控制器中的新操作。辅助方法甚至没有被执行。我是过去的大师,擅长把事情复杂化,谁能帮我解开这个问题?

4

1 回答 1

0

您是否为该操作设置了路线store?如果你这样做了,那么你应该在你的表单标签中使用 url 帮助器:

form_tag( results_store_url )
于 2012-07-10T23:42:25.850 回答