# Passing context with request?

**URL:** <https://www.ruby-forum.com/t/passing-context-with-request/175018>\
**Category:** Rails\
**Created:** [September 6, 2009, 3:27am UTC](https://www.ruby-forum.com/t/passing-context-with-request/175018 "2009-09-06T03:27:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@Glen](https://www.ruby-forum.com/u/Glen)\
**Post date:** [September 6, 2009, 3:27am UTC](https://www.ruby-forum.com/t/passing-context-with-request/175018/1 "2009-09-06T03:27:55Z")

</div>

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 `[]’

---

<div class="post-metadata">

**Author:** ![Glen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@Glen](https://www.ruby-forum.com/u/Glen)\
**Post date:** [September 6, 2009, 3:58am UTC](https://www.ruby-forum.com/t/passing-context-with-request/175018/2 "2009-09-06T03:58:57Z")

</div>

On Sep 6, 2:26 am, Glen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Glen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@Glen](https://www.ruby-forum.com/u/Glen)\
**Post date:** [September 6, 2009, 4:12am UTC](https://www.ruby-forum.com/t/passing-context-with-request/175018/3 "2009-09-06T04:12:25Z")

</div>

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

On Sep 5, 7:57 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
