1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#José,

#Ok.. so I am setting the current_user and current_domain using a before_filter in the application controller.

#In the model Task belongs to :user, :job, :domain.

class TasksController < InheritedResources::Base
  belongs_to :user, :job, :optional => true
  
  respond_to :html, :js, :xml

  protected
    def begin_of_association_chain
      @domain
      @current_user
    end
end

#This works fine as long as i don't nest the association. If I want the domain and current user to be passed through on create i have to do:

class TasksController < InheritedResources::Base
  belongs_to :user, :job, :optional => true
  respond_to :html, :js, :xml

 def create
     @task = end_of_association_chain.new( params[:task] )
     @task.domain = @domain
     @task.domain
     @task.user = @current_user
     create! 
  end

  protected
    def begin_of_association_chain
      @domain
      @current_user
    end

end

#Any way thanks, you're work is unbelievably good.  I describe Inherited resources as magic.   


#P.S. Is there a way to pass @domain to the model using "has_scope" 

has_scope :pay_period

named_scope :pay_period, lambda { |date| { :conditions => [ 'date BETWEEN ? AND ?', @domain.pay_period(date)[:start], @domain.pay_period(date)[:stop] ] } }

#
#