Forum: Ruby on Rails Submitting a remote form without any rendering.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3df897745c664e3add6f047daa5835d1?d=identicon&s=25 MenDAKE (Guest)
on 2007-04-07 01:23
I imagine there's a simple solution for this. I want to click a checkbox
and have a rails for submit immediately and save data to the database.
However, since this is a checkbox there's no need to render anything
because either the checkbox is check or it's not.

For example:

<%= form_remote_tag(:url => { :action => "save_data" }) %>
<%= check_box("report", "word", :onclick => "this.form.submit()") %>
<%= end_form_tag %>

Then in the controller I have a method called "save_data" that does the
usual active record saving of data, but I don't need any rendering to be
done -- I just need the data to be saved. If I leave out the "render
:partial" statement I'm obviously told the template for "save_data" is
missing. How can I get around this?
C6858f4b8ec263c8c3c58759494e926a?d=identicon&s=25 Andy Delcambre (Guest)
on 2007-04-07 01:42
(Received via mailing list)
On 4/6/07, MenDAKE <rails-mailing-list@andreas-s.net> wrote:
> <%= end_form_tag %>
>
> Then in the controller I have a method called "save_data" that does the
> usual active record saving of data, but I don't need any rendering to be
> done -- I just need the data to be saved. If I leave out the "render
> :partial" statement I'm obviously told the template for "save_data" is
> missing. How can I get around this?

  # Renders an empty response with status code 200
  render :nothing => true

 - Andy Delcambre
3df897745c664e3add6f047daa5835d1?d=identicon&s=25 MenDAKE (Guest)
on 2007-04-07 01:58
Andy Delcambre wrote:
> On 4/6/07, MenDAKE <rails-mailing-list@andreas-s.net> wrote:
>> <%= end_form_tag %>
>>
>> Then in the controller I have a method called "save_data" that does the
>> usual active record saving of data, but I don't need any rendering to be
>> done -- I just need the data to be saved. If I leave out the "render
>> :partial" statement I'm obviously told the template for "save_data" is
>> missing. How can I get around this?
>
>   # Renders an empty response with status code 200
>   render :nothing => true
>
>  - Andy Delcambre

Thanks, that looks like what I need.

However, now I have another question. It seems that putting a
form.submit inside the Onclick of a checkbox doesn't render the form
ajax style. Instead of updating the div with the appropriate id the
entire page is updated. Am I going about this wrong?
This topic is locked and can not be replied to.