Menu
  • HOME
  • TAGS

cancel default controller action's redirect

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....

Override the respond_to format with form button in rails 3

ruby-on-rails-3,respond-to

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...

respond_to and service objects

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...

Trying to alias old method and create new one in ruby

ruby,respond-to

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.

how to DRY a respond_to that is the same in all actions?

ruby-on-rails,ruby,respond-to

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...