John Merlino wrote:
> Frederick Cheung wrote:
>> On Jan 12, 4:58 pm, John Merlino <[email protected]> wrote:
>>>
>>> > Your lambda should return a single hash with all the query options you
>>> > want. (and its :joins not :join)
>>>
>>> > Fred
>>>
>>> Isn't it returning a single hash here?
>> 
>> No it isn't - you've got the :join => :student_state and then you've
>> got the lambda - you can't mix and match the proc form of named_scope
>> with the non proc form: either you pass a hash to named_scope or you
>> give it a lambda - not both.
>> 
>> Fred
> 
> Well, I changed it around. I think this is what you were talking about:
> 
> class StudentState < ActiveRecord::Base
> has_many :students
> end
> 
> class Student < ActiveRecord::Base
> belongs_to :student_state
> named_scope :status, :joins => :student_state, => {'student_state.state' 
> => ?, :state}
> end
> 
> 
> 
> class StudentsController < ApplicationController
> 
> before_filter :get_state
> 
> def index
>  @list = student.find(:all)
>  render :xml => @list
> end
> 
> def filter_show
>  @student_state.student.status(:state)
> #This is the students associated with a student state and based on which 
> value they click on, we will return that value into the status 
> named_scope, which will set it and then only return the students of the 
> student_status which has a value of that specific state (e.g. 
> passing/failing)
> end
> 
> def get_state
> @student_state= StudentState.find(params[:all])
> #All of the attributes of student_state model (e.g. status attribute and 
> values of passing/failing)
> end
> 
> All I was trying to do was where a user clicks on one of options in a 
> filter, such as passing, then it will return the list of students who 
> are passing. My undertanding is this could be done in named_scope.

Actually, ignore above. This to me makes sense as to how it should work:

class StudentState < ActiveRecord::Base
has_many :students
end

class Student < ActiveRecord::Base
belongs_to :student_state
named_scope :status, :joins => :student_state, => {'student_state.state' 
=> ? = student_state.students.state_id, :state}
end



class StudentsController < ApplicationController

before_filter :get_state

def index
 @list = student.find(:all)
 render :xml => @list
end

def filter_show


 @filter = @student_state.students.status(:state) #This is the students 
associated with a student state and based on which value they click on, 
we will return that value into the status named_scope, which will set it 
and then only return the students of the student_status which has a 
value of that specific state (e.g. passing/failing)
end
 render :xml => @filter
end
def get_state
@student_state= StudentState.find(:all) #All of the attributes of 
student_state model (e.g. status attribute and values of 
passing/failing)
end
-- 
Posted via http://www.ruby-forum.com/.
-- 
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