javascript,ruby-on-rails,redirect,respond-to
Actually, after reading this, I must do the justice and post the officially recommended way of handling this case. The action should read: def close @ticket = Ticket.find(params[:id]).update_attribute(:status, "closed") head :ok end Thank you, @auL5agoi, for leading me to this answer....
I can finally respond to my own question, now. So here's the answer: I figured out how this can be accomplished. You can set the name of the buttons to be "format" and set the value to the extension that you would append to the URL. <%= button_tag( 'HTML', :value...
ruby-on-rails,ruby-on-rails-4,controller,respond-to,service-object
respond_to and send_file should remain in your controller, but the rest of the logic can be moved into the service object. First, make the service object return the temp_file: class UserReportService def initialize(user) @user=user end def user_report_generate # Initialize DocxReplace with your template doc = DocxReplace::Doc.new("#{Rails.root}/lib/docx_templates/my_template.docx", "#{Rails.root}/tmp") # Replace some...
I bet you call alias_method inside the scope of Sinatra::Base. You should call it inside the singleton class of Sinatra::Base, because the method get is defined as a class method.
I would write a single action that takes the "view" as a parameter. You're basically doing a #show action that renders different views. get 'widgets/:template', to: 'widgets#show' class WidgetsController < ApplicationController def show respond_to do |format| format.html { render params.require(:template) } format.js { render js: js_constructor } end end private...