I’ve changed my destructive link_to statements in
favor of button_to.
But what if I want to make an .rjs call with that button?
Seems like we need something equivalent to link_to_remote,
so that the button can make an ajax request instead submitting
the form.
I’ve made pretty extensive use of form_remote_tag for this. I just
don’t
put any user input elements inside, although I do sometimes put hidden
fields inside to pass param values. Just be aware that you can’t use it
inside another form like you can with link_to_remote.
button_to takes a javascript function… so pass in
an ajax function to call using remote_function…
Could you say more about this, please? What do you mean “button_to
takes a
javascript function”? I wasn’t able to find anything about that when I
went
though the exercise. I still don’t see it but would really like to know
how
it could be made to work. A snippet would be excellent!
I’ve been working on much the same problem, but I have a form that
when I submit it I want to only reload part of the page. I tried
working it like I have other ajax/RJS calls, but it doesn’t seem to
work from a submit_tag. I don’t know the name of the javascript
function that the rjs creates so I don’t know how to call it.
I’ve made pretty extensive use of form_remote_tag for this. I just don’t
put any user input elements inside, although I do sometimes put hidden
fields inside to pass param values. Just be aware that you can’t use it
inside another form like you can with link_to_remote.
Maybe you can help me with a related question, then… when I try a
simple remote form like this:
Title:
<%= text_field 'product', 'title' %>
<%= submit_tag "Add New Product" %>
<% end %>
This will call my create action just fine as expected; but
unfortunately it will respond_to html, not js, and hence render the
wrong template! Is this the correct behavior? I don’t think it is.
Did I do something wrong in the above code?
This will call my create action just fine as expected; but
unfortunately it will respond_to html, not js, and hence
render the wrong template! Is this the correct behavior?
Sorry, but I’m not sure I’m following you. I’m guessing you’re saying
you’re using respond_to in your create action and that it’s rendering an
RHTML template instead of the RJS template you expect. Is that right?
If
so, the problem is probably in how you’ve coded the respond_to. I took
me
some time to get my arms around that. A little sandbox time goes a long
way. Create a new sandbox, cut the code down to the bare minimum needed
to
get the behavior that you’re testing. If you’re still in need, I’m
happy to
take a look at the controller and view code at that point if you want to
post it.
This will call my create action just fine as expected; but
unfortunately it will respond_to html, not js, and hence
render the wrong template! Is this the correct behavior?
Also make sure that you’ve included the required javascript in your
layout. Something like:
<%= javascript_include_tag :defaults %>
If I remember correctly I was having a similar problem to yours and
the reason was that I wasn’t including javascript.
isn’t the whole point of button_to to make sure you support non-JS
users? [well, mebbe not the whole point.] you could probably just
add custom js to a regular button_to and have both rjs fun and not
leave non-JS users out in the cold.
RSL
On Thu, Jul 17, 2008 at 6:48 AM, Ricardo Villalobos