Passing parameters on rails

Hi, I want to know how I can pass the following parameters …
I have
faculdade: id, name
curso : id, faculdade_id

and the following code

#view

<%= select(:curso, :faculdade_id , Faculdade.find(:all).collect {|c|
[c.nome, c.id] }) %>

Preço do Curso

controller

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

if I try to do it manually (with /cursos/lista_faculdade?teste=3 for
example it works
all I need to know is how to pas the parameter from the select to the
href link
Thanks in advance! =*

On 3 Apr 2008, at 18:35, Laura Laizer smith wrote:

<%= select(:curso, :faculdade_id , Faculdade.find(:all).collect {|c|
[c.nome, c.id] }) %>

Preço do Curso

controller

You’ll need to use some javascript to do that, unless you use a form
(you can always style the button to look like what you want).

Fred

Yes, look into observe_field in the API, and you could easily write a
small RJS template which replaced the link with one with the
appropriately inserted value.

Julian.

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

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/

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:

<%= 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 ?

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 !

On 4 Apr 2008, at 16:07, Laura Laizer smith 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

Frederick C. wrote:

On 4 Apr 2008, at 16:07, Laura Laizer smith 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 C. wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs