Hey all, I keep getting a syntax error somewhere in this code. Thanks for all help. class StudentState < ActiveRecord::Base has_many :students end class Student < ActiveRecord::Base belongs_to :student_state named_scope :filtertabs, :join => :student_state, lambda { |*args| {:conditions => {''student_state.id => ?'', args}} } end class StudentsController < ApplicationController before_filter :get_status def index @list = student.find(:all) render :xml => @list end def filter @students = @student_state.students.filtertabs.find(:all) render :xml => @students end def get_status @student_state = StudentState.find(params[:id]) 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 12, 2:25 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> {:conditions => {''student_state.id => ?'', args}} }This is wrong - I assume you meant ''student_state.id'' => args Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jan 12, 2:25 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> {:conditions => {''student_state.id => ?'', args}} } > > This is wrong - I assume you meant ''student_state.id'' => args > > FredAfter I change it to: named_scope :filtertabs, :join => :student_state, lambda { |*args| {:conditions => {''student_state.id'' => args}} } I still get a syntax error. -- Posted via http://www.ruby-forum.com/. --0015174c3ff258eb63047cf91f44 Content-Type: text/plain; charset=ISO-8859-1 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --0015174c3ff258eb63047cf91f44--
On Jan 12, 3:15 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote:> After I change it to: > > named_scope :filtertabs, :join => :student_state, lambda { |*args| > {:conditions => {''student_state.id'' => args}} } > > I still get a syntax error.Your lambda should return a single hash with all the query options you want. (and its :joins not :join) Fred> -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jan 12, 3:15 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Frederick Cheung wrote: > >> After I change it to: >> >> named_scope :filtertabs, :join => :student_state, lambda { |*args| >> {:conditions => {''student_state.id'' => args}} } >> >> I still get a syntax error. > > Your lambda should return a single hash with all the query options you > want. (and its :joins not :join) > > FredIsn''t it returning a single hash here? @student_state = StudentState.find(params[:id]) -- Posted via http://www.ruby-forum.com/. --000325558e160d70ab047cfa906c Content-Type: text/plain; charset=ISO-8859-1 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --000325558e160d70ab047cfa906c--
On Jan 12, 4:58 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: > > On Jan 12, 3:15 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> Frederick Cheung wrote: > > >> After I change it to: > > >> named_scope :filtertabs, :join => :student_state, lambda { |*args| > >> {:conditions => {''student_state.id'' => args}} } > > >> I still get a syntax error. > > > 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> @student_state = StudentState.find(params[:id]) > -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jan 12, 4:58 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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. > > FredWell, 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. -- Posted via http://www.ruby-forum.com/. --00032555412ae7b0fe047cfbe5e7 Content-Type: text/plain; charset=ISO-8859-1 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --00032555412ae7b0fe047cfbe5e7--
John Merlino wrote:> Frederick Cheung wrote: >> On Jan 12, 4:58 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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/. --0022158df84f5b276b047cfc11c7 Content-Type: text/plain; charset=ISO-8859-1 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --0022158df84f5b276b047cfc11c7--
On 12 Jan 2010, at 18:46, John Merlino wrote:>> >> 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} >> endNot quite - since you''ve got a parameter you have to use the lambda form (when I said you had to use the hash form or the lambda form I was talking in generalities), so you need named_scope :status, lambda {|...| { :conditions => ..., :joins => ... } Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On 12 Jan 2010, at 18:46, John Merlino wrote: >>> => ?, :state} >>> end > > Not quite - since you''ve got a parameter you have to use the lambda form > (when I said you had to use the hash form or the lambda form I was > talking in generalities), so you need > > named_scope :status, lambda {|...| { :conditions => ..., :joins => ... } > > Frednamed_scope :status, lambda { |key| { :joins => :student_state, :conditions => ["student_state.key = ?", key], :limit => 20 } } The above ended up working. However, I thought that the inner join I specified would make the attributes of student_state available in the xml output of the students controller (when going to the url http://localhost:3000/students.xml). But it wasn''t. Is this a limitation of rail''s xml capabilities? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 13, 2:06 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> The above ended up working. However, I thought that the inner join I > specified would make the attributes of student_state available in the > xml output of the students controller (when going to the urlhttp://localhost:3000/students.xml). But it wasn''t. Is this a limitation > of rail''s xml capabilities?The :joins / :includes specified when you fetch rows have no bearing on xml (or json etc) output, however to_xml does accept options that allow you to do that sort of stuff. Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.