Note that there are some explanatory texts on larger screens.

plurals
  1. POrails radiobutton auto submit
    text
    copied!<p>I want to be able to set the <code>:albumcover</code> of the image object to TRUE or FALSE. How do I accomplish this with ajax so that it submits when the radio button is checked? Thanks so much!</p> <p><strong>View</strong> </p> <pre><code>&lt;% @images.each do |image| %&gt; ... &lt;%= label(:albumcover, 'Set as Album Cover ', :style =&gt; "float: left;") %&gt; &lt;%= radio_button_tag(:albumcover, "cover", false, :id =&gt; :albumcover_tag) %&gt; ... &lt;% end %&gt; </code></pre> <p><strong>Routes</strong></p> <pre><code>Admin::Application.routes.draw do get "albums/index" get "dashboard/index" namespace :admin do root :to =&gt; "dashboard#index" resources :dashboard resources :albums do resources :images do member do get :ajax_update put :update_form end end end get "admin/album" end get "logout" =&gt; "sessions#destroy", :as =&gt; "logout" get "login" =&gt; "sessions#new", :as =&gt; "login" get "signup" =&gt; "users#new", :as =&gt; "signup" # resources :users resources :basic root :to =&gt; "basic#index" </code></pre> <p><strong>Attempted Ajax</strong></p> <pre><code>$(function(){ $('#albumcover_tag').bind('click', function(){ $.ajax({ url: "&lt;%= update_form_admin_album_images_path %&gt;", data: $('#albumcover_tag').val(), }).success(function(){ alert("success"); }); }); }); </code></pre> <p><strong>Schema Table</strong></p> <pre><code>create_table "images", :force =&gt; true do |t| t.string "title" t.string "description" t.datetime "date" t.integer "album_id" t.integer "image_id" t.binary "picture" t.boolean "albumcover" end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload