我希望能够将图像对象的: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"
尝试使用Ajax
$(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