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

How can I access UrlWriter url/path generators from a model's class method?

I want to generate urls from a model's class method. I've done this before from an instance method by simply including ActionController::UrlWriter -- I tried including this in the instance definition scope and also the class definition scope, to no…
John Bachir
  • 22,495
  • 29
  • 154
  • 227
2
votes
0 answers

Extend ActionController::Base within an application

I'd like to expose a method to my controllers and views in the same fashion that plugins like Devise and Sorcery expose a current_user method. In fact I am piggybacking on this very functionality. However my attempts to divine the proper syntax for…
Frank Koehl
  • 3,104
  • 2
  • 29
  • 37
2
votes
3 answers

Why are unnecessary instance variables a bad practice?

I have heard several times that creating unnecessary instance variables is bad practice, but can't figure out why it is a bad practice? What effects does it have if we use unnecessary instance variables in our application? Any help would be…
2
votes
2 answers

How the object of controller classes is created in Rails?

When we navigate through pages in a rails app, inturn we call one of the functions defined in the controller class. Lets say we access localhost:3000/articles/new then new action (method) of the ArticlesController class is called/invoked.It's…
amritesh
  • 83
  • 6
2
votes
1 answer

ActionController::UrlGenerationError in Valuations#new

I've read other SO articles relating to UrlGenerationError's which seem to point to singularization or plurization of a word, but I don't think that's the issue here. It works when I remove from valuations/_form.html.erb: <%= render…
2
votes
1 answer

Devise Registration not showing "some" nested form fields Rails 4

I've got a modified Devise "sign_up" form (new registration) that includes fields for child and grandchild objects to be created along with the user. All of the model relationships are set up properly with access to the child's attributes. However,…
2
votes
2 answers

Rails not rendering 404 in production

I have a rails app. When in production my app is throwing a routing error instead of rendering the 404.html or 500.html. Why would Rails be throwing the error instead of rendering the 404 page? (output from dev with…
Jake
  • 383
  • 6
  • 26
2
votes
2 answers

Different code in same controller action for html or json

I have a controller action that responds to the same root in two formats - html and json. But the code that runs for the html response is completely different than the one for the json response.. Now I have something like def index result_html =…
Yo Ludke
  • 2,149
  • 2
  • 23
  • 38
2
votes
1 answer

Rails 4: Accessing model through another

I'm having trouble accessing the Picture model setup like: Request has_one Gallery has_many Pictures From the show view of the Request model, I need to access its Gallery's Pictures, and it's giving me the error undefined method 'pictures' for…
domi91c
  • 1,962
  • 4
  • 23
  • 38
2
votes
1 answer

Rails update_attributes not working

In my Rails app, update_attribute seems not working. I'm trying to update a boolean field called billed. The same command works great for two other tables. Output of rails console: >> Expense.find(28).update_attributes(:billed => true) => false >>…
Reddirt
  • 5,913
  • 9
  • 48
  • 126
2
votes
2 answers

Multiple update forms for one model

I want to have multiple forms on one page. Let's make an example to understand what I want: I have a page for my admins, let's say it's the admins#show page. My admin has to change his name on one form on this page and on another form his age. I…
Tommy
  • 2,355
  • 1
  • 19
  • 48
2
votes
1 answer

Emit JSON error output instead of HTML for JSON requests

My team is using a hypermedia API built on top of collection+JSON using our modified collection+JSON gem. We would prefer to see this when there is an error and the request format is JSON: { collection: { error: { 'title':…
MustModify
  • 657
  • 10
  • 20
2
votes
3 answers

class variables and module inclusion, specifically in ActionController

I want to have some kind of single list that is initialized in a seperate module, then can be included in a controller and modified at the controller-class level, and accessed at the controller-instance level. I thought class variables would work…
Tim Snowhite
  • 3,736
  • 2
  • 23
  • 27
2
votes
2 answers

Is it possible to define ActionController::Base in many different controllers?

If you had an OrdersController, could you define the class like this? class OrdersController < ActionController::Base # stuff end When I generate a Rails scaffold, the only place this seems to be defined is in the…
2
votes
1 answer

Create bare rails controller class

I'm trying to create clean controller based on ActionController::Base. That's what I try: class MetalController ActionController::Base.without_modules(:ParamsWrapper, :Streaming).each do |left| include left end end From Rails…
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103