Ruby Hash wierdness

K

Kev Jackson

Hi

I'm having problems with using a hash. I put in a class and when I
retrieve it, it's automagically become a string

ie

<%= button_link _("Export CSV"),
SearchParams.get_url_hash({ :action => :export_csv, :klass =>
Customer }, params, @search_fields) %>

Customer is a class that is available to my view


def export_csv
klass = params[:klass]
cond = SearchParams.get_search_conditions(klass, params, @search_fields)
set_csv_headers(klass)
csv_export(klass, cond)
end

but here klass (and params[:klass]) is a string? What I really want to
do is

<%= button_link _("Export CSV"),
SearchParams.get_url_hash({ :action => :export_csv(Customer) },
params, @search_fields) %>

Any ideas why my lovely Customer class is being butchered into a string :(

Kev
 
R

Robert Klemme

Kev said:
Hi

I'm having problems with using a hash. I put in a class and when I
retrieve it, it's automagically become a string

ie

<%= button_link _("Export CSV"),
SearchParams.get_url_hash({ :action => :export_csv, :klass =>
Customer }, params, @search_fields) %>

Customer is a class that is available to my view


def export_csv
klass = params[:klass]

Try

klass = Object.const_get(params[:klass])
cond = SearchParams.get_search_conditions(klass, params,
@search_fields) set_csv_headers(klass)
csv_export(klass, cond)
end

but here klass (and params[:klass]) is a string? What I really want
to
do is

<%= button_link _("Export CSV"),
SearchParams.get_url_hash({ :action => :export_csv(Customer)
}, params, @search_fields) %>

Any ideas why my lovely Customer class is being butchered into a
string :(

Probably because there is an HTTP request in between?

robert
 
D

Dr Nic

Yep, urls only contains strings. Often horribly ugly ones with %20 etc
all through it, but they are strings.

I like the Object.const_get method - cleaner and more specific than an
eval etc.

Nic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,052
Latest member
EvaW192252

Latest Threads

Top