passing parameters on rails

Just also of interest, is this:

def lista_faculdade     teste = params[:teste]    @faculdade_teste = Curso.find(:all).select do |student|    student.faculdade_id = teste    end

You should probably be using Curso.find_by_faculdade_id(teste) as this
will put the searching at the database level (this is what databases
are good at), and not force Rails to load the entire dataset into
memory to only then filter it back using Ruby's select iterator.

Julian.

Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) VIDEO #3
OUT APRIL 6 http://sensei.zenunit.com/

You should probably be using Curso.find_by_faculdade_id(teste) as this will put the searching at the database level (this is what databases are good at), and not force Rails to load the entire dataset into memory to only then filter it back using Ruby's select iterator.

thanks i will be studying now and see how far I can get !

Laura Laizer smith wrote:

You should probably be using Curso.find_by_faculdade_id(teste) as this will put the searching at the database level (this is what databases are good at), and not force Rails to load the entire dataset into memory to only then filter it back using Ruby's select iterator.

thanks i will be studying now and see how far I can get !

I tried the following

#view

Search: <input type="text" id="faculdade_find" name="search" /> <div id="results"></div>

<%= observe_field 'faculdade_find',   :frequency => 0.5,   :update => 'results',   :url => { :controller => 'curso', :action=> 'lista_faculdade' },   :with => "'search_text=' + escape(value)"%>

#controller

def lista_faculdade     teste = params['search_text']     @faculdade_teste = Curso.find(:all).select do |curso|     curso.nome_curso = teste     end     @curso_pages, @cursos = paginate_collection @faculdade_teste, :per_page => 10 end   def show     @curso = Curso.find(params[:id])   end

but it's not finding, instead it's changing the name of all cursos ... Can someone tell me what am I doing wrong ?

def lista_faculdade    teste = params['search_text']    @faculdade_teste = Curso.find(:all).select do |curso|    curso.nome_curso = teste

I suspect you want curso.nome_curso == teste, otherwise as you note
you will just be assigning (and since you are assigning non null
values you are effectively selecting them all)

Fred

Frederick Cheung wrote:

def lista_faculdade    teste = params['search_text']    @faculdade_teste = Curso.find(:all).select do |curso|    curso.nome_curso = teste

I suspect you want curso.nome_curso == teste, otherwise as you note you will just be assigning (and since you are assigning non null values you are effectively selecting them all)

Fred

Half of my problems are solved I can do search now but if I try Math for instance it opens 4 frames inside the frame of app to then do the math search the same number of letter I type the same frames it open inside the application I think I am doing something very stupid But I dont know what ...

Laura Laizer smith wrote:

Frederick Cheung wrote:

You are doing it inside a for condition .... Dunno you can replace it but when you use do it's a iteration...