Active Admin with Ajax call

Hello everyone. I’m begining with Ruby on Rails, and i’m facing some
trouble with “ActiveAdmin with ajax.”

Here’s the situation:
It’s a Kennel’s web site, so, while i’m creating a new dog, i have one
select/options for the dog’s father, dog’s mother, and dog’s race.

After select the dog’s father/mother “i can be able” to know the race
from
the dog i’m creating, so i need to dynamically fill the race’s option,
accordinggly with his father’s or mother’s race.

I know i need a javascript/ajax, and i know hot to do it with php “i
know
it’s pretty simple” but as i’m new with Ruby on Rails, i don’t know
where
and how to write these codes in active admin.

If anyone could help, thanks so much! =)

On May 17, 2013, at 3:35 PM, Bruno Sapienza wrote:

Hello everyone. I’m begining with Ruby on Rails, and i’m facing some trouble
with “ActiveAdmin with ajax.”

Here’s the situation:
It’s a Kennel’s web site, so, while i’m creating a new dog, i have one
select/options for the dog’s father, dog’s mother, and dog’s race.

After select the dog’s father/mother “i can be able” to know the race from the
dog i’m creating, so i need to dynamically fill the race’s option, accordinggly
with his father’s or mother’s race.

I know i need a javascript/ajax, and i know hot to do it with php “i know it’s
pretty simple” but as i’m new with Ruby on Rails, i don’t know where and how to
write these codes in active admin.

If anyone could help, thanks so much! =)

If you’re beginning with RoR, I would seriously encourage you to first
build an entire site with nothing but the core Rails framework – no
extras at all. I tried using Hobo very early in my Rails career, and I
feel like it set me back quite a ways. These engines and meta-frameworks
enforce their own logic on top of Rails’ and this can cause you to miss
some basic concepts that you will need later. Walk then run, IOW.

Walter

On May 19, 2013, at 11:36 AM, Walter Lee D. wrote:

I know i need a javascript/ajax, and i know hot to do it with php “i know it’s
pretty simple” but as i’m new with Ruby on Rails, i don’t know where and how to
write these codes in active admin.

If anyone could help, thanks so much! =)

If you’re beginning with RoR, I would seriously encourage you to first build an
entire site with nothing but the core Rails framework – no extras at all. I tried
using Hobo very early in my Rails career, and I feel like it set me back quite a
ways. These engines and meta-frameworks enforce their own logic on top of Rails’
and this can cause you to miss some basic concepts that you will need later. Walk
then run, IOW.

Here’s an article that really expands on this idea.

You might give it a quick read and see if you agree with my premise.

Walter

Walter

I already builded an entire site and also an admin panel with RnR,
(with
really simple ajax), and i’m doing great stuff with active admin in this
current project, the only problem is the ajax.

As you said, these tools enforce their own logic on top of Rails, and
this
is my problem, how to do it with active admin?

Maybe i have missed something, and anyway i apreciate your link, and i
sure
will read it, and do the examples, but if you could explain directly
about
how to do what i need directly in active admin, i would be really
greatful!

Thanks so much!

On May 20, 2013, at 8:40 AM, Bruno Sapienza wrote:

I wish I had some snippet I could share here, but I haven’t ever used AA
so I don’t know in how many ways it differs from “vanilla” Rails in this
regard. Have you read the Rails Guides about using the unobtrusive
listeners in Rails 3?

(Not sure why this isn’t listed in the regular guides, but there you go.
Just skip the part about TurboLinks since that isn’t in Rails 3.x
without an extra gem.)

Now that gets you the basics of the Rails helpers for unobtrusive
JavaScript. The trick in your case will be to figure out how you would
structure your request if you weren’t using JS, then add the JS response
layer over the top of that. What would the URL look like if you were
just asking the server to build a picker containing all of the races for
the parent? See if you can get the server to return an HTML response
containing a single select picker alone in the page. Then make a
respond_to option that returns a JSON hash of the options instead, and
use your JavaScript to update the options in the second picker. (Don’t
just replace the second picker, you’ll be stuck in a never-ending-loop
of having to re-attach your unobtrusive listeners, as they are removed
along with the original iteration of that second picker.)

Walter

On May 20, 2013, at 8:40 AM, Bruno Sapienza wrote:

Walter

I already builded an entire site and also an admin panel with RnR, (with really
simple ajax), and i’m doing great stuff with active admin in this current project,
the only problem is the ajax.

As you said, these tools enforce their own logic on top of Rails, and this is my
problem, how to do it with active admin?

Maybe i have missed something, and anyway i apreciate your link, and i sure will
read it, and do the examples, but if you could explain directly about how to do
what i need directly in active admin, i would be really greatful!

Thanks so much!

Start here:
http://www.alfajango.com/blog/rails-3-remote-links-and-forms/

(Just found that in the footer links on the aforelinked Rails Guide.)

Walter