0

This is a rather simple Rails 4 situation. Model Intranet has_many activities. Activities exists with sufficient records for several intranets. Current_intranet.activities.size returns 69 records. However, whenever I try to access any of the records, I receive "output error: <ArgumentError: wrong number of arguments (1 for 0)" even though I'm not passing any arguments. All of the following fail with that error.

Current_intranet.activities.first
Activity.where(intranet_id: 1).first
Activity.where(:intranet_id => 1).first
Activity.where{intranet_id.eq 1}.first
All of the above with [0] instead of first

There is no problem with any other models I'd appreciate any suggestions. Thanks in advance.

There are no defined scopes. The code is:

class Activity < ActiveRecord::Base
  acts_as_capitalized

  # activities created during intranet creation.  
  DEFAULT_ACTIVITIES = { 'Document Preparation' => 'general income', 'No Charge' => 'general income'}

  # static activity names that can not be deleted.
  STATIC_ACTIVITY_NAMES = [ 'Document Preparation','No Charge']

  before_destroy :check_if_used
  before_destroy :cannot_delete_static_activities

  belongs_to :created_by_user, :class_name => "User", :foreign_key => "created_by"
  belongs_to :updated_by_user, :class_name => "User", :foreign_key => "updated_by"

  belongs_to :intranet
  belongs_to :chart_of_account  

  has_many :activity_rates, :dependent => :destroy
  has_many :event_type
  has_many :billings do 
    def find_by_name(name)
      (find :all, :conditions => ["activity.name = ?",name])
    end
  end

  has_many :document_templates, :foreign_key => "billing_activity_id"

  validates_presence_of :intranet_id, :name, :chart_of_account_id
  validates_uniqueness_of :name, :scope => :intranet_id
Paul Richter
  • 10,908
  • 10
  • 52
  • 85
UnConundrum
  • 1
  • 1
  • 3
  • Is `Current_intranet` an instance variable, or is that a constant / class? – Paul Richter Feb 10 '14 at 20:45
  • What are you trying to do with this line? `Activity.where{intranet_id.eq 1}.first` That syntax looks incorrect. – steakchaser Feb 10 '14 at 20:57
  • It was in console. I'm just trying to access the data in the first record.. or any record for that matter. A .each fails as well. As to the syntax, that's squeal. I'm pretty sure it's correct. – UnConundrum Feb 10 '14 at 21:05
  • Can you post the `Activity` model? – steakchaser Feb 10 '14 at 21:11
  • it is predominantly Rails 2 code that I'm converting to 4. I can't seem to post the code as it's longer than the character limit. – UnConundrum Feb 10 '14 at 21:18
  • Just post the associations and any scopes – steakchaser Feb 10 '14 at 21:34
  • @user2000664 Not in the comments; just edit the original question and add it in there. Code isn't formatted (and becomes pretty unreadable) in the comments. – Paul Richter Feb 10 '14 at 21:48
  • Well, I've stumbled on some progress, but I don't understand the underlying issue. Activity.where(intranet_id: 1).first still does not work, but if I add the field name as a symbol, it does. IOW Activity.where(intranet_id: 1).first[:name] properly returns the name from the first record, while Activity.where(intranet_id: 1).first.name continues to return the same error – UnConundrum Feb 10 '14 at 22:33
  • 2
    Does something like `last` raise the same errors as `first`? Have you accidentally defined a `first` method anywhere in your Activity model? – sevenseacat Feb 11 '14 at 02:50
  • Last, second, third all generate the same problem. – UnConundrum Feb 11 '14 at 20:18

0 Answers0