Ajax and Rails

Hello, I have been trying to use ajax and rails for a drop down list and
I can’t seem to get it to work.

This is what I am looking for, I have a drop down list, and as soon as
the user selects an option, I want it to dissapear and make my content
between the div I specified appear on the form.

I have like 3 different divs with different content in them for each
drop down item.

I have tried to do it with RJS and declaring my own javascript functions
but I can’t seem to get it to work.

Any help would be appreciated please?

Thanks

Hi Matthew,

Matthew L. wrote:

I have been trying to use ajax and rails for a drop
down list and I can’t seem to get it to work.

What do you mean ‘can’t seem to get it to work’? What is it doing / not
doing. Where’s the relevant code? We can’t help much without more
info.

Bill

Bill W. wrote:

Hi Matthew,

Matthew L. wrote:

I have been trying to use ajax and rails for a drop
down list and I can’t seem to get it to work.

What do you mean ‘can’t seem to get it to work’? What is it doing / not
doing. Where’s the relevant code? We can’t help much without more
info.

Bill

Sorry hehe, well when I click on the item I want, I tried to put an
observer on the select id=“mediaType”, then i wanted to put in my RJS
template something like if page[:mediaType][:value] = ‘Game’
page.remove ‘mediaType’
page.show ‘form_game’
end

I wanted to do that for all my mediaType items

Matthew L. wrote:

Sorry hehe, well when I click on the item I want, I tried
to put an observer on the select id=“mediaType”,

Is the observer firing? What do you see in Firebug when you click an
item?

then i wanted to put in my RJS template something like
if page[:mediaType][:value] = ‘Game’

What is this? Is this how you’re trying to get the value returned when
the
user makes a selection? Cause it ain’t the way to do it. Post the
relevant
code from the view that generates the request, the controller method
that
gets invoked, and the RJS template. Then we can give you some guidance.

Have you worked with RJS before? If not, I highly recommend Cody
Fauser’s
PDF at O’Reilly: “RJS Templates”. It’s $10 you’ll be glad you spent.

Best regards,
Bill

Bill W. wrote:

Matthew L. wrote:

Sorry hehe, well when I click on the item I want, I tried
to put an observer on the select id=“mediaType”,

Is the observer firing? What do you see in Firebug when you click an
item?

then i wanted to put in my RJS template something like
if page[:mediaType][:value] = ‘Game’

What is this? Is this how you’re trying to get the value returned when
the
user makes a selection? Cause it ain’t the way to do it. Post the
relevant
code from the view that generates the request, the controller method
that
gets invoked, and the RJS template. Then we can give you some guidance.

Have you worked with RJS before? If not, I highly recommend Cody
Fauser’s
PDF at O’Reilly: “RJS Templates”. It’s $10 you’ll be glad you spent.

Best regards,
Bill

Ok here’s my controller code:

class ClientController < ApplicationController
scaffold :client

def change

end
end

my view code:

Release Name:

Release Type:

Game Music Movie
Genre:

and I do the same thing for music and movie with different inputs

and here is my RJS ‘change.rjs’ template code:

I was doing something like

if page[:mediaType][:value] = ‘Music’
page.remove ‘mediaType’
page.show ‘music_form’
end

I did this for game and movie too

I would buy the book but I don’t have a credit card :slight_smile:

Thanks

Hi Matthew,

No offense intended, but after seeing your code I think you ought to
work
through a basic tutorial or two to get your arms around Rails’ basics
before
you tackle RJS. The cookbook tutorial at O’Reilly that Curt and I did
is
pretty much up to date. It’s at

Best regards,
Bill

Bill W. wrote:

Hi Matthew,

No offense intended, but after seeing your code I think you ought to
work
through a basic tutorial or two to get your arms around Rails’ basics
before
you tackle RJS. The cookbook tutorial at O’Reilly that Curt and I did
is
pretty much up to date. It’s at
Radar – O’Reilly

Best regards,
Bill

I’ve already done that, I already made some exercises with that and they
worked fine, its just I’m having trouble in using ajax, I know how to
use my models and controllers and to make my custom views its just I
want to learn more with ajax. I have already made some examples that I
insert data into 2 different tables and databases on the same form thats
not my problem.