I would like the submit button action to execute a rails method or a rake task on the server side. The task copies the records from one model to another. I intend to add the button to the bottom of the index view of the pages controller.
I've read some posts but still can't figure out how to use the remote_function. Also tried using :onclick => :make_assets but nothing happens. Thanks
e.g. radio_button :model, :method, :onclick => remote_function(:controller => 'some', :action => 'action')
lib/tasks/move_photo.rake
namespace :db do
desc "Move records from photos to assets"
task :movephoto => :environment do
Rake::Task['db:migrate'].invoke
make_assets
end
end
def make_assets
Photo.all.each do |photo|
newasset = nil
newasset = Asset.create!(:user_id => photo.user_id,
:image => photo.image)
photo.destroy unless newasset.nil?
end
end
/app/controllers/photos_controller.rb
def make_assets
Photo.all.each do |photo|
newasset = nil
newasset = Asset.create!(:user_id => photo.user_id,
:image => photo.image)
photo.destroy unless newasset.nil?
end
end
/app/views/photos/index.html.erb
<%= will_paginate %>
<%= will_paginate %>
<%= submit_tag 'Approve', :onclick => remote_function(:controller => :photos, :action => :make_assets) %>