Ruby on Rails Saturday, April 30, 2011

On 30 April 2011 18:00, David Mr. <lists@ruby-forum.com> wrote:
> Colin Law wrote in post #995918:
>> On 29 April 2011 22:40, David Mr. <lists@ruby-forum.com> wrote:
>>>>> /home/brad/Documents/blogazer/app/models/search.rb:201:in
>>> Here is the code from around line 201 in search.rb:
>>>
>>> def set_from_sources(sources)
>>>  final = Set.new
>>>   sources.each do |source|
>>
>> The error suggests that sources is not a collection
>>
>>>   p = Page.find_by_id source
>>>   h = YAML.load(p.data)
>>>   final.merge h.keys
>>>  end
>>>  final
>>> end
>>>
>>> Here is line 107 in search.rb:
>>> gamma[:D] = set_from_sources(gamma[:C]) - (txv[:a] + txv[:b])
>>
>> So gamma[:C] is not a collection.  Have a look at the Rails Guide on
>> debugging and find how to use ruby-debug to break into your code so
>> you can examine gamma.
>>
>> Colin
>
> OK.  I used debugger and found that 'setax and 'setbx' are nil instead
> of being assigned the strings in 'setA.split(" ")' and setB.split(" ").
>
> Using debugger I verified that setA has the proper string value entered
> at the form.
>
> Even if I change the code to setax = setA, setax is always nil.
>
> Does the fact that setA and setB are in the Attribute-Accessor list make
> a difference in the way I should assign other variables their value?
>
> Here is the code:
>
> class Search < ActiveRecord::Base
>  belongs_to :project
>  has_one :user, :through => :project
>
>  attr_accessor :setA, :setB, :setAList, :setBList, :google

First I would stick to the Rails conventions when naming things, so
these should be set_a and so on.

>  before_create :setup_data
>  before_save :setup_data
>  def setup_data
>   debugger
>    setax = []
>    setbx = []

You don't need the above as split will return an array

>    setax = setA.split(" ")
>    setbx = setB.split(" ")

Are you saying that this method gets called ok but at this point,
checked in the debugger, that setA has a sensible value but setax does
not?

It might help also if you explained whether any of the variables are
db columns and which are just instance variables.

Colin

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment