我是新來的rails,我目前使用2.3.8。我正在爲iOS應用程序設計一個Web服務。在Ruby on Rails 2.3.x中發送參數到GET請求
因爲我通常是客戶端iPhone開發人員,所以我對服務器端實現的知識非常少。
我遇到的問題是,我試圖將GET請求中的某些參數傳遞給我的控制器之一中的索引操作。這是使用默認路由
map.resources :dishes
其中碟子是控制器的名稱,使用腳手架創建。
我想通過多個參數到一個新的動作或索引,這將允許我篩選菜餚對象返回。
索引方法看起來像
def index
if(params[:latitude])
@min = 0.5 - 1
@max = 0.5 + 1
@locations = Location.find(:all, :conditions => [":latitude > ? AND :latitude < ?", @min, @max])
@dishes = new Array
@locations.each do |loc|
@dishes = @dishes + loc.dishes
end
respond_to do |format|
format.html # index.html.erb
format.json {render :json => @dishes.to_json(:except => [ :user_id, :location_id , :like_id], :include => { :user => { :only => [:id, :name] } } ) }
end
else
@dishes = Dish.all
respond_to do |format|
format.html # index.html.erb
format.json {render :json => @dishes.to_json(:except => [ :user_id, :location_id , :like_id], :include => { :user => { :only => [:id, :name] } } ) }
end
end
end
我目前收到以下錯誤,當我通過一個額外的PARAM
ArgumentError in DishesController#index
wrong number of arguments (1 for 0)
完整的錯誤:
ArgumentError in DishesController#index
wrong number of arguments (1 for 0)
RAILS_ROOT: /Users/jon/Documents/Dev/Research/FF5_Rails_Test/FF5
Application Trace | Framework Trace | Full Trace
/Users/jon/Documents/Dev/Research/FF5_Rails_Test/FF5/app/controllers/dishes_controller.rb:9:in `new'
/Users/jon/Documents/Dev/Research/FF5_Rails_Test/FF5/app/controllers/dishes_controller.rb:9:in `index'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in `perform_action_without_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/filters.rb:617:in `call_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Library/Ruby/Gems/1.8/gems/activesupport- 2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/flash.rb:151:in `perform_action'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `process_without_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/filters.rb:606:in `process'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/base.rb:391:in `process'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/base.rb:386:in `call'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/routing/route_set.rb:438:in `call'
Request
Parameters:
{"format"=>"json",
"latitude"=>"0.5"}
Show session dump
Response
Headers:
{"Content-Type"=>"",
"Cache-Control"=>"no-cache"}
我知道這與Rails的RESTful設計略有不同,但我無法找到另一種方式來實現它。
再一次,我是一個新的rails/web服務開發,所以如果你有任何提示,我會歡迎他們。
謝謝。
我假設你正在做'/盤?緯度= ..'的請求嗎? – rdvdijk
是的,抱歉,我應該讓那一個清楚。 –
如果您沒有看到代碼,您應該發佈索引操作中的所有代碼以查找錯誤 – Bohdan