Questions tagged [actioncontroller]

ActionController is the main controller class in Ruby on Rails.

ActionController is the main controller class in Ruby on Rails.

424 questions
13
votes
1 answer

after_filter for exceptions

Is there something similar to an after_filter that still runs if the action raises an exception? I'm using an external logger (since I'm on Heroku); the response headers are filtered and logged in the after_filter. If an exception is raised, the…
Andrew C
  • 431
  • 1
  • 5
  • 8
13
votes
2 answers

Why is Rails before_filter called twice when the controller is subclassed?

I'm at Rails 2.3.5 and I have this problem: class BaseController < ApplicationController before_filter :foo, :only => [:index] end class ChildController < BaseController before_filter :foo, :only => [:index, :show, :other, :actions] end The…
12
votes
1 answer

Running threads inside my rails controller method

I've got a set of data that I'd like to do some calculations on inside my rails application, each calculation is independent of each other so I'd like to thread them so my response is much faster. Here's what I've got ATM: def show @stats =…
TheDelChop
  • 7,938
  • 4
  • 48
  • 70
11
votes
1 answer

Rails 3: Proper way to Delete resource using respond_with

I'm trying to DRY up a controller by incorporating respond_with. When I do, following some instructions in a Railscast, I get things mostly working. The problem lies in the redirect after deleting a resource...which should be redirecting to…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
11
votes
2 answers

Best way to catch :abort signal thrown in Rails 5 controller

In Rails 5, when a callback needs to cancel later callbacks, the recommended process is documented as "you should explicitly throw :abort." My question is: how is it recommended that this exception be caught? My current solution is to catch…
sameers
  • 4,855
  • 3
  • 35
  • 44
11
votes
2 answers

Rails "action" params key conflict

I am building a RESTful Rails service with various CRUD endpoints. On one of the Create endpoints, the data I am passing in includes: ... action: "action_name" ... The problem I am having is that params[:action] contains "create", not the actual…
Jeremy Blalock
  • 2,538
  • 17
  • 23
10
votes
2 answers

RoR - Which is preferred - Rack Middleware or Active Controller Filters?

For the latest version of Ruby on Rails (4 at the time of asking this question), what is the preferred way to implement code that modifies the request/response such as an authentication mechanism. I see many sites and tutorials advocating Rack…
10
votes
5 answers

How to access a Rails controller view context from outside of a controller?

I am working on cleaning up some code that relies on some custom controller helper methods, by creating a "plain old Ruby" presenter object. In my controller, I am able to pass the view context to the class: def show # old code:…
Andrew
  • 227,796
  • 193
  • 515
  • 708
10
votes
2 answers

How to allow Binary File download using GRAPE API

I want to allow downloading a binary file (.p12 file) using ruby's Grape API. This is what I am trying. get '/download_file' do pkcs12 = generate_pkcsfile content_type('application/octet-stream') body(pkcs12.der) end The equivalent code…
boboverflow
  • 309
  • 4
  • 10
9
votes
1 answer

Rails 6 - constant ActionController::InvalidAuthenticityToken

I'm tinkering with Rails 6 and I am constantly getting ActionController::InvalidAuthenticityToken on forms generated by rails, such as (implementing the rails tutorial book register/login flow) <%= form_for(@user, url: 'signup') do |f| %> <%=…
9
votes
3 answers

Ruby on Rails - When to use params.permit! and how to replace it

I'm working on a legacy rails application and the controllers have many instances of params.permit!. When running a Brakeman scan on it, params.permit! opens up the application to mass assignment vulnerabilities. My question is- what is the most…
zasman
  • 446
  • 1
  • 8
  • 28
9
votes
2 answers

How to download CSV data using ActionController::Live from MongoDB?

I have created a CSV downloader in a controller like this format.csv do @records = Model.all headers['Content-Disposition'] = "attachment; filename=\"products.csv\"" headers['Content-Type'] ||= 'text/csv' end Now I want to create server…
user5710450
9
votes
1 answer

Rails 4.2 ActionController:BadRequest custom error message

I want to return from my controller if either a validation failed or a parameter is missing with 400 - bad request. So in my controller if have if params["patch"].nil? then raise ActionController::BadRequest.new( "The Json body needs to be…
theDrifter
  • 1,631
  • 6
  • 24
  • 40
9
votes
3 answers

Rails ActionController unknown format

I am trying to render a xlsx file. But I keep getting a 406/UnknowFormat. I have done the right setup, maybe im missing something? Rails 4.2 app gem 'axlsx' gem "axlsx_rails" gem 'zip-zip' config/initializers/mime Mime::Type.register…
Seal
  • 1,060
  • 1
  • 12
  • 31
9
votes
4 answers

rescue_from ::AbstractController::ActionNotFound not working

I have the following code: unless Rails.application.config.consider_all_requests_local rescue_from Exception, with: :render_exception rescue_from ActiveRecord::RecordNotFound, with: :render_exception rescue_from…
1
2
3
28 29