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

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

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

to_query

Fred