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
2
votes
3 answers

How to get segment keys from a Rails 3 route?

I need to determine the number of route segment keys in the current path for an application I'm working on, and despite digging around for a bit in the related Rails 3 source files, I can't figure it out. I know how to use url_for and request to…
coreyward
  • 77,547
  • 20
  • 137
  • 166
2
votes
2 answers

Getting access to :not_found, :internal_server_error etc. in Rails 3

It looks like ActionController::StatusCodes has been removed from Rails 3. I used synonyms for HTTP status codes such as 200 => :ok 404 => :not_found 500 => :internal_server_error For more codes, see…
rmk
  • 4,395
  • 3
  • 27
  • 32
2
votes
1 answer

Can Rails action redirect *with* JSON payload?

I have a Rails endpoint that redirects with url parameters. The code is really simple: def success_redirect redirect_to "#{success_url}/#{encoded_params}" end My colleague hopes I could make the same redirect, but send parameters as JSON…
Matilda Smeds
  • 1,384
  • 11
  • 18
2
votes
0 answers

Does every Rails request instantiate new Helper modules?

I know every request to a Rails app instantiates a new controller for the request, so the controller itself is thread safe. So, if I make a request to /users, the UsersController for example will be a new instance. However, UsersController inherits…
David
  • 7,028
  • 10
  • 48
  • 95
2
votes
4 answers

Rails 5 - Manually add attribute to parameters in controller when updating

I am trying to manually add an additional attribute to parameters in the controller after completing a form. The params seem to be wrapped in , which seems to be preventing me to from changing the params. Controller: class ActualsController <…
Matt Ellis
  • 143
  • 2
  • 2
  • 16
2
votes
1 answer

How do I create multiple copies of a nested model as specified in it's `quantity` attributes

Question For a nested model, how do I create multiple copies of it, as specified in it's quantity attribute. Usecase This is especially done when making invoices. If your invoice is a model, and the line items are nested models with a quantity…
2
votes
2 answers

Calling a CommandController from ActionController in PHP/TYPO3 Extbase

I wrote a Command Controller that handles data import from an URL. pseudo-syntax is like this: class ImportCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController { public function importCommand($auth){ $data =…
2
votes
2 answers

In controller's action `params = params.merge({})` raises NoMethodError: undefined method `merge' for nil:NilClass

I am upgrading my Ruby 2.3.1 / Rails 4.2.5.1 to Rails 5.0.0.1 and I am encountering a strange error when running a controller spec for my following controller: In my controller I have following code: class Api::InboundSmsCallbackController <…
2
votes
0 answers

undefined method 'database field' for 'model'

error: thrown from the form undefined method `profession_id' for # env: Rails: 5.0.0.1 Ruby: 2.2.4 form.html.erb <%= f.collection_select(:profession_id, @professions, :id, :title, {:include_blank => true, :prompt =>…
iamtoc
  • 1,569
  • 4
  • 17
  • 24
2
votes
1 answer

Force encoding on ActionController::Parameters

I'm attempting to save the params from PayPal's IPN so they can be accessed later and used for cross reference. Simple little bit of code that saves it in the paypal_log column: @order.paypal_log = params.to_json Worked fine, pushed to production…
user4778326
2
votes
1 answer

What is the most Rails'ish way of handling multiple layouts/views for the same controller action?

The scenario is this: I have some users on my site. A user has a role, the relevant ones here is admin and normal. I also have a model, let's call it SomeModel. I have created a backend for the site, which uses an admin layout. All admins have full…
rhardih
  • 863
  • 1
  • 10
  • 18
2
votes
1 answer

Register a different type of callback in ApplicationController

I need more fine grain control on the order of callbacks in my controllers. Currently Rails only let you use append|prepend_before|after_action, but this is just extremely bad if you want to add a module with its dedicated callbacks. I am trying to…
2
votes
2 answers

ActionController::RoutingError No route matches [DELETE]

I'm writing a page that shows a news feed and having trouble with deleting a post. When I tried to delete a certain post, it will give me an error: ActionController::RoutingError (No route matches [DELETE] "/news.305"): for example (305 being the…
Evilmuffin
  • 214
  • 4
  • 14
2
votes
1 answer

render_to_string with url params

I have a sidekiq worker, which should render a file and save it. In the rendering process via render_to_string i pass a bunch of instance variables and variables like current_user, which works fine. But to render my view I also need url parameters…
Jan
  • 12,992
  • 9
  • 53
  • 89
2
votes
1 answer

When upgrading to Rails 4.2.3 I get "NameError: uninitialized constant ActionController::Responder"

I have made quite a few gem upgrades, to get my railsversion up to 4.2.3. But when I try to access my app (running on a Pow server) I now get the following error: Your Rack app raised an exception when Pow tried to run it. NameError: uninitialized…
Cjoerg
  • 1,271
  • 3
  • 21
  • 63