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
72
votes
9 answers

How to set config.action_controller.default_url_options = {:host = '#''} on per environment basis

Right now I'm using this which works for the development host, but I have to manually change the {:host => ""} code when I move to production. post.rb def share_all url = Rails.application.routes.url_helpers.post_url(self, :host =>…
trying_hal9000
  • 4,343
  • 8
  • 43
  • 62
40
votes
2 answers

Does Rails come with a "not authorized" exception?

I am writing an application that uses plain old Ruby objects (POROs) to abstract authorization logic out of controllers. Currently, I have a custom exception class called NotAuthorized that I rescue_from at the controller level, but I was curious to…
Rick
  • 8,366
  • 8
  • 47
  • 76
39
votes
4 answers

how to handle exceptions in JSON based RESTful code?

I have a "software as a service" app that uses JSON communicated via a RESTful API. Simply stated: what are the best practices for capturing and reporting exceptions when using a RESTful API with JSON data interchange? My first thought was to see…
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
35
votes
9 answers

Rails 3: Get current namespace?

using a method :layout_for_namespace I set my app's layout depending on whether I am in frontend or backend, as the backend is using an namespace "admin". I could not find a pretty way to find out which namespace I am, the only way I found is by…
arnekolja
  • 1,687
  • 5
  • 22
  • 29
34
votes
1 answer

Threading error when using `ActiveRecord with_connection do` & ActionController::Live

Major edit: Since originally finding this issue I have whittled it down to the below. I think this is now a marginally more precise description of the problem. Comments on the OP may therefore not correlate entirely. Edit lightly modified version…
31
votes
5 answers

Accessing UserManager outside AccountController

I am trying to set the value of a column in aspnetuser table from a different controller (not accountcontroller). I have been trying to access UserManager but I can't figure our how to do it. So far I have tried the following in the controller I…
26
votes
4 answers

rescue_from ActionController::RoutingError in Rails 4

I've got the following error: ActionController::RoutingError (No route matches [GET] "/images/favicon.ico") I want to show error404 page for links that are not existing. How can I achieve that?
23
votes
2 answers

skip_before_action and Rails 5

I just upgraded to Rails 5 and everything went pretty smoothy but for no apparent reason a method that is called after skip_before_action is not allowing rspec to run with this message Before process_action callback :redirect_heroku_user has not…
Bitwise
  • 8,021
  • 22
  • 70
  • 161
21
votes
7 answers

How do I configure the hostname for Rails ActionMailer?

I'm working on a fairly traditional forgot password email - I want to email the user a password change token embedded in a link that they can click on in order to change their password. I'm emailing via the traditional ActionMailer. If I use a…
edebill
  • 7,655
  • 5
  • 32
  • 31
19
votes
1 answer

Specifying format: "xml" ignored with render_to_string

I have an action that needs to render a view to string. The view is called index.xml.erb. I am trying to achieve this with render_to_string: my_string = render_to_string(layout: false, format: "xml") render_to_string is instead rendering the…
YWCA Hello
  • 2,997
  • 4
  • 29
  • 40
18
votes
3 answers

how to execute an action if the before_action returns false

I know that with the following code: before_action :signed_in?, only: [:new] the action new will be executed if the signed_in? returns true, but instead if I want the new action to be executed when signed_in? returns false what do I have to do? Do I…
zer0uno
  • 7,521
  • 13
  • 57
  • 86
17
votes
5 answers

default_url_options and rails 3

As ActionController::Base#default_url_options is deprecated, I wonder how to set default url options in rails3. The default url options are not static but dependent of the current…
gucki
  • 4,582
  • 7
  • 44
  • 56
17
votes
3 answers

Rails ActionController Execute Same Code for Every Action

To the rails experts out there I was wondering where/how you would execute the same code for every action in your web application? If you can point me to an article or provide a short code snippet I would greatly appreciate it. Thanks in advance to…
Brian DiCasa
  • 9,369
  • 18
  • 65
  • 97
15
votes
2 answers

Rails ActionController: Difference between request.remote_ip and request.remote_addr

In the ActionController source, local requests are defined as follows: def local_request? #:doc: request.remote_addr == LOCALHOST && request.remote_ip == LOCALHOST end In my application, I want to use different logic if requests are coming from…
jrdioko
  • 32,230
  • 28
  • 81
  • 120
14
votes
2 answers

Rails 4 has_one association form not building

I need some pointers on how Rails 4 works with has_one and belongs_to association. My form doesn't save the has_one relationship Post Model class Post < ActiveRecord::Base validates: :body, presence: true has_one :category, dependent: :destroy …
1
2 3
28 29