我正在尝试将记录保存在数据库中。许多列值将从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
我一直被重定向到结果控制器中的新操作。辅助方法甚至没有被执行。我是过去的主人,过于复杂的事情,任何人都可以帮我解开这个问题吗?
答案 0 :(得分:0)
您是否为store
行动设置了路线?如果您这样做,则应在表单标记中使用url helper:
form_tag( results_store_url )