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

ActionController::RoutingError (Couldn't find..., expected it to be defined in...)

So...first time asking a question to StackOverflow... I converted an existing Rails 4.2.5 app (using Ruby 2.2.4) to a Rails 5.1.3 app (using Ruby 2.4.1), following the Rails Guides and the RailsApps Project. Firing up the development server…
TKChattoraj
  • 111
  • 1
  • 6
5
votes
2 answers

Rails 5.0.0beta3: ActionController::InvalidAuthenticityToken in development

I have just started a simple app with a couple of forms on Rails 5.0.0beta3. In development, using http://localhost:3000 on Safari or Chrome to access the app, if I fill a form and submit it I always get an ActionController::InvalidAuthenticityToken…
5
votes
3 answers

How to use Rails Action Controller Nested Params to Permit a Specific Attributes Hash

There are a lot of questions about Nested Parameters, but I can't seem to find one that addresses my specific, simple situation. I'm trying to permit a nested hash that is NOT an array. I expected this to work: params.require(:book).permit(:title,…
readyornot
  • 2,783
  • 2
  • 19
  • 31
5
votes
2 answers

Does ActiveModel::Serializer require an explicit render call?

I know that when using view templates (html, rabl), I don't need an explicit render call in my controller action because by default, Rails renders the template with the name corresponding to the controller action name. I like this concept (not…
5
votes
1 answer

Rails root_url has two forward slashes when default_url_options trailing_slash is true

When this line is set in the application.rb file: config.action_controller.default_url_options = { trailing_slash: true} The root_url contains two forward slashes: www.example.com// Without that line we get: www.example.com The reason we have this…
silasjmatson
  • 1,814
  • 18
  • 37
5
votes
0 answers

how can you test the 'catch all route' using ordinary controller tests?

Note: As per RafaeldeF.Ferreira's suggestion, this question has been heavily edited since its original form. My JSON-based app needs to return something sensible when given a bad route. We already know that the following rescue_from…
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
4
votes
1 answer

How to prevent force_ssl from destroying params in redirect?

I have the following route: resources :widgets do resources :orders end so that a request, e.g. to /widgets/1/orders/new goes to OrderController, which can access params[:widget_id] to know which widget is being purchased. The problem is this: I…
4
votes
2 answers

How do I unit test the zend action controller?

I need to rapidly build good software in php and using the zend framework. I try to go at this in a TDD way because its people more experienced than me told me that was the best way to rapidly build while keeping your code manageable. So I got the…
Bram
  • 765
  • 1
  • 6
  • 14
4
votes
2 answers

list and create on one page rails 3

I want to make a dashboard page with on top a create action (form) and underneath it a list action... (to display all the questions that have been made) I was wondering what is the best way to do this. I have a QuestionsController with a list and a…
4
votes
1 answer

Rails 6 ActionController::TestCase stub a controller method

I am new with Ruby/Rails and the testing frameworks within Ruby/Rails. I have a pre-validation method (external API) that validates the incoming request. For all test cases, I want to stub that call and test the remaining functionalities. I am…
4
votes
1 answer

Rails: .require() without actually requiring it?

I'm trying to use... params.require(:subscriber).permit(:utm_source, :utm_medium, :utm_campaign, :utm_term, :utm_content) The problem is there are rare occasions where I want to do: Subscriber.new(subscriber_params) And I don't care if all the…
4
votes
2 answers

Rails memory leak: controller class holding a reference to instance

I have a memory leak in a Rails 4.2.6 application. A controller allocates a large GaragesPresenter object as an instance variable, which should be de-referenced and garbage collected after the request completes. However, I see that this never…
davidgyoung
  • 63,876
  • 14
  • 121
  • 204
4
votes
0 answers

Rails default charset for request body

I've built an API endpoint with rails that accepts an XML payload in the request body. The XML has UTF8 characters in it but the client making the request didn't specify the charset in their Content-Type header so my controller is treating the…
Adam Langsner
  • 1,276
  • 1
  • 15
  • 23
4
votes
1 answer

set default_url_options on initialize

I need to force the host in one of the environments in my rails app. I've can get the override to work by including def default_url_options(opts={}) opts.merge({:host => 'stg.my-host.com'}) end in app/controllers/application.rb But is there…
Ben K.
  • 1,779
  • 5
  • 18
  • 21
4
votes
1 answer

Creating nested models in Rails 4 forum app

Hello I am making a Forum application in Rails 4. It can have numerous forums, each with numerous topics. Each topic can have many posts. When creating a new topic, one must also create the initial post, much like Stack Overflow itself. Therefore, I…