I should mention that the Hash does contain the Objective's data. the
reason it is important that Objective is returned instead of Hash is
because I want to be able to call methods on it.

On Oct 24, 8:31 am, drewB <[email protected]> wrote:
> I am running into a very odd problem.  I have an ActiveRecord called
> Objective with a public create method.  When this method is called in
> a controller the return value is a Hash instead of Objective.  When I
> test the method in Rspec for the model it returns as Objective.
>
> Does anyone have an idea about why the return type would be different
> and if so how to fix it so it always returns Objective?
>
> Code:
>
> class Objective < ActiveRecord::Base
>   belongs_to :user
>   has_many :next_actions, :order => 'id DESC', :conditions =>
> {:completed => false}
>   has_many :action_items, :order => 'position'
>   has_many :progress_updates
>
>   serialize :freq_value
>
> validates_presence_of :name, :due_date, :completion, :pr_u_frequency_id
>   validates_numericality_of :completion, :only_integer =>
> true, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 100
>
> def self.create(attributes, user_id)
>     #create new record with user_id correctly set
>     attributes.delete :freq_options #deletes this unused key
>     obj = self.new(attributes)
>     obj.user_id = user_id
>     obj.save ? obj : nil
>
>   end
>
> end
>
> class ObjectivesController < ApplicationController
>   before_filter :require_user
>
>   layout false
>
>   def create
>     objective = Objective.create(params[:objective], current_user.id)
>     Rails.logger.info("****objective.class = #{objective.class}****")
>   end
> end
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to