Passing context with request?

I’m having trouble passing context data with a request. Rails keeps
complaining that it can’t convert string to integer which is
questionable in and of it’s self. Origionally the data was being
added to the query string as a string so I thought it might be an
encapsulation issue and sent them as actual integers but it seems to
make no difference. Here is the code:

This is the action in the first controller:

def show
@jobs = Job.all(:conditions => [“city_id = ? AND region_id = ? AND
country_id = ?”, params[:city], params[:region], params[:country]])
@city = City.find(params[“city”])
@region = Region.find(params[“region”])
@country = Country.find(params[“country”])
@companies = []
@titles = []

@jobs.each do |job|
  @companies << job.company
end

@companies.uniq!

@jobs.each do |job|
  @titles << job.title
end

@titles.uniq!

end

This is the link that is causing the problem (it is in the show view
for the action above):

<%= link_to title, by_title_jobs_url(:title => title, :location =>
[:city => @city.id, :region => @region.id, :country => @country.id])
%>

And here is the action being called by the link:

def by_title
if params[:location]
@jobs = Job.find(:all, :conditions => [“title = ? AND city_id = ?
AND region_id = ? AND country_id = ?”, params[“title”], params
[“location”][“city”], params[“location”][“region”], params[“location”]
[“country”]])
elsif params[:company]
@jobs = Job.find(:all, :conditions => [“title = ? AND company_id
= ?”, params[“title”], params[“company”]])
else
@jobs = Job.find(:all, :conditions => [“title = ?”, params
[“title”]])
end
end

I repeatedly get the following error message:

TypeError in JobsController#by_title

can’t convert String into Integer

RAILS_ROOT: /Users/fenris/Projects/Rails/jobsnob
Application Trace | Framework Trace | Full Trace

/Users/fenris/Projects/Rails/jobsnob/app/controllers/
jobs_controller.rb:46:in `[]’

On Sep 6, 2:26 am, Glen [email protected] wrote:

I’m having trouble passing context data with a request. Rails keeps
complaining that it can’t convert string to integer which is
questionable in and of it’s self.

The error you’re getting means “I’m an array and you trying to access
a string index”. You get the same error if you do [1,2,3][‘foo’] in
the console
I’d check that the parameters you receive are what you expected (did
you really mean to use [] in your link_to call ?)

Fred

Thanks Fred, passing location as a hash works much better.

On Sep 5, 7:57 pm, Frederick C. [email protected]