On Apr 23, 1:32 pm, "Miguel A." <[email protected]> wrote:
>
>
> if params[:fc].present?
> arel=arel.joins('INNER JOIN facilities_hotels ON
> hotels.id=facilities_hotels.hotel_id ')
>
> for i in params[:fc].size
> arel=arel.where('facilities_hotels.facility_id = ?',
> params([:fc][i]))
> #how do I increment on the previous line? Obviously
> params([:fc][i]) does not work
> end
Typically I would just do
params[:fc].each do |fc_id|
...
end
To iterate over an array like that.
This doesn't do what you want though, since rails will be and-ing all
of the conditions
You probably want where(:facilities_hotels => {:facility_id =>
array_of_ids}) which will generate a IN clause
Fred
> arel
> else
> arel
> end
>
> else
> all
> end
>
> I didn't want to do this with to_sql...
>
> Also, when i run it, the query always returns empty results if I check a
> facilities checkbox, but maybe that is a problem from that line of code
> in my model but if you forsee an issue, I would appreciate a heads up in
> terms of future code conflict relating to this issue
>
> Thank you in advance
>
> --
> Posted viahttp://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.