How do I pass an array in a URL? such that at the other end rails will see it as an Array?

Hi,

How do I pass an array in a URL? such that at the other end rails will
see
it as an Array?

I’m trying to use the following bit of ActiveScaffold code:

  params.reject {|key, value| [:controller, :action,

:id].include?(key.to_sym)}.each do |key, value|
next unless
active_scaffold_config.model.column_names.include?(key)
if value.is_a?(Array) <=== WHEN I TRY TO CREATE A URL WITH
AN ARRAY AS A PARAMETER VALUE IT ALWAYS COMES OUT AS A STRING???
conditions = merge_conditions(conditions,
["#{active_scaffold_config.model.table_name}.#{key.to_s} in (?)",
value])
else
conditions = merge_conditions(conditions,
["#{active_scaffold_config.model.table_name}.#{key.to_s} = ?", value])
end
end

thanks in advance

On Aug 6, 2:34 am, “Greg H.” [email protected]
wrote:

Hi,

How do I pass an array in a URL? such that at the other end rails will see
it as an Array?

You need to use the right naming convention for your parameters. See
http://www.spacevatican.org/2008/7/18/parametrised-to-the-max

Fred

thanks for the pointer & use of
“ActionController::AbstractRequest.parse_query_parameters” to test.
Do you know a Rails or Ruby method that can be used to convert an Array
or
Hash to the form required for a URL? (e.g. in my case I’ll be a view
wanting to create a URL to a Rails controller/action but with URL
parameters
including some that are Arrays).

Thanks

On Wed, Aug 6, 2008 at 5:37 PM, Frederick C.
<[email protected]

Perhaps use JSON, combined to to the CGI escape method ( h() in rails’s
views)

2008/8/6 Greg H. [email protected]

On Aug 6, 9:12 am, “Greg H.” [email protected]
wrote:

thanks for the pointer & use of
“ActionController::AbstractRequest.parse_query_parameters” to test.
Do you know a Rails or Ruby method that can be used to convert an Array or
Hash to the form required for a URL? (e.g. in my case I’ll be a view
wanting to create a URL to a Rails controller/action but with URL parameters
including some that are Arrays).

to_query

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs