Rails controller/routing question
I am new to RoR and I cant get one of my rotes to work, not sure whats going on? I have defined a route in my routes.rb file, somthing like this...
map.connect 'myurl/:someid/:start/:limit', :conditions => { :method => :get }, :controller => 'mycontroller', :action => 'get_data_list'
# method defintion in mycontroller
def get_data_list (someid, start, limit)
render :text => "Blah"
end
And I am using the following the url to invoke the above route and it does not work? Any clue? http://host:port/myurl/24/1/10
It gives the following error. Looks its reached the controller action, but fails after that??
Processing Mycontroller#get_data_list (for 127.0.0.1 at 2010-07开发者_JAVA技巧-12 19:07:45) [GET] Parameters: {"start"=>"1", "limit"=>"10", "someid"=>"24"}
ArgumentError (wrong number of arguments (0 for 3)):
This is what you want:
map.connect 'myurl/:someid/:start/:limit', :conditions => { :method => :get }, :controller => 'mycontroller', :action => 'get_data_list'
# method defintion in mycontroller
def get_data_list
someid = params[:someid]
start = params[:start]
limit = params[:limit]
render :text => "Blah"
end
You don't need the (someid, start, limit) part of the method in your controller. Those variables are accesses by params[:someid], based on your route. The ArgumentError is because the controller method is expecting variables that aren't being passed to it.
精彩评论