1

我希望能够将:albumcover图像对象的设置为 TRUE 或 FALSE。如何使用 ajax 完成此操作,以便在选中单选按钮时提交?非常感谢!

看法

<% @images.each do |image| %>
...
  <%= label(:albumcover, 'Set as Album Cover ', :style => "float: left;") %>
  <%= radio_button_tag(:albumcover, "cover", false, :id => :albumcover_tag) %>
...
<% end %>

路线

Admin::Application.routes.draw do
  get "albums/index"

  get "dashboard/index"

  namespace :admin do
    root :to => "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" => "sessions#destroy", :as => "logout"
  get "login" => "sessions#new", :as => "login"
  get "signup" => "users#new", :as => "signup"
    # resources :users
  resources :basic
    root :to => "basic#index"

尝试阿贾克斯

$(function(){
$('#albumcover_tag').bind('click', function(){
    $.ajax({
        url: "<%= update_form_admin_album_images_path %>",
        data: $('#albumcover_tag').val(),
    }).success(function(){
        alert("success");
    });
});
});

模式表

create_table "images", :force => 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
4

0 回答 0