Topic: Why cant I do params[:search] = session[:search] ?

For  params[:search] = session[:search] I get the error undefined method `stringify_keys!' for #<Search:0x3bf44c0>...

Any ideas?

Re: Why cant I do params[:search] = session[:search] ?

Can you log out whats in params[:search] and session[:search]?  Thats where I would start, see what they actually contain smile

I think you do

logger.debug 'text'

Re: Why cant I do params[:search] = session[:search] ?

Good suggestion!

OK I did not have a params hash in the first place so I added params = Hash.new before params[:search] = session[:search] but I still get the same error message. I also I think this problem goes a little deeper.

If in the console I do:

search = Search.new
another_search = Search.new(search)

I get the same error, Im sure this should not generate an error??

This is the same as doing, which also give the same errors:

search = Search.new(Search.new)

or

search = Search.new
search.update_attributes(Search.new)

Both of which give the same error.


The session looks like this:

:search: &id001 !ruby/object:Search 
  attributes:
    city: Newark
    start_station_name: City, Beastmarket Hill
    leave_time: 2006-07-19 13:17:00 +01:00
    leave_date: 2006-07-19 00:00:00 +01:00
    end_station_name: Clifton, Nottm Trent Uni
    return_day: Wednesday
    return_time: 2006-07-19 18:17:00 +01:00
    return_date: 2006-07-19 00:00:00 +01:00
    start_station_id:
    service_type: "0"
    leave_day: Wednesday
    end_station_id:
  errors: !ruby/object:ActiveRecord::Errors
    base: *id001
    errors: {}
  new_record: true
flash: !map:ActionController::Flash::FlashHash
  :notice: Please try searching again...

Last edited by afm (2006-07-19 08:48:35)

Re: Why cant I do params[:search] = session[:search] ?

Looks like it has no idea what the Search model is, If you don't have a Model called Search then thats likely to cause big problems smile  Might need a bit mor info on the search though to be a bit more helpfull

Re: Why cant I do params[:search] = session[:search] ?

I have a model called Search and it must know what it is otherwise search = Search.new would throw an error.

irb:
s = Search.new
s.class => Search

Re: Why cant I do params[:search] = session[:search] ?

I'm not sure if I'm understanding your question correctly, however in the case of the code below

search = Search.new
another_search = Search.new(search)

The problem is that ActiveRecord::Base doesn't provide a copy constructor.  Ie you can't pass an instance of one model to the the new and get a duplicate instance.  AR::Base.new expects a single hash, if anything, as its parameter.  Thus you'd need to massage the existing object into an attribute hash before using in in new, such as
search = Search.new
another_search = Search.new(search.attributes)

I suspect you're running into a similar problem in the original post, at some point you're using an object where the code expects a hash.

My RoR journey  -- thoughts on learning RoR and lessons learned in applying TDD and agile practices.

Re: Why cant I do params[:search] = session[:search] ?

I think you are right about it expecting a hash... The problem will dynamically typed languages wink
However the answer was a very simple:

@search = session[:search]


Just before trying this I also tried:

@search = Search.new
@search.update_attributes(session[:search].attributes) => false

I would have though this would have worked since .attributes returns a full hash.
Anyway...