From: Ladislav Martincik lmartinc@redhat.com
--- src/app/helpers/application_helper.rb | 18 ++++++++++++++++++ src/config/environment.rb | 3 +++ 2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/src/app/helpers/application_helper.rb b/src/app/helpers/application_helper.rb index e48851c..37330cb 100644 --- a/src/app/helpers/application_helper.rb +++ b/src/app/helpers/application_helper.rb @@ -172,4 +172,22 @@ module ApplicationHelper end end end + + # Integration of rack-restful_submit convention to be able to call + # RESTful resources defined by Rails conventions without Javascript. + # + # Method generates 3 tags: + # * 2 hidden field tags to define URL and METHOD to be forwared to in RESTful env. + # * 1 submit field to trigger the form submission defining the action + # + # Example: + # <tt>restful_submit_tag('Delete', 'destroy', instance_path(@instance), 'DELETE')</tt> + # + # Learn more: https://github.com/martincik/rack-restful_submit + def restful_submit_tag(value, action, url, method) + hidden_field_tag("__map[#{action}][url]", url) << + hidden_field_tag("__map[#{action}][method]", method.upcase) << + submit_tag(value, :name => "__rewrite[#{action}]") + end + end diff --git a/src/config/environment.rb b/src/config/environment.rb index 7d8ba2c..07c0ea0 100644 --- a/src/config/environment.rb +++ b/src/config/environment.rb @@ -52,6 +52,9 @@ Rails::Initializer.run do |config| config.gem "simple-navigation" config.gem "typhoeus" config.gem "rb-inotify" + config.gem 'rack-restful_submit' + + config.middleware.insert_after Rack::MethodOverride, 'Rack::RestfulSubmit'
config.active_record.observers = :instance_observer, :task_observer # Only load the plugins named here, in the order given. By default, all plugins