You cannot use a before_request hook for specific views, not in the same app. Your options are to: Use a separate Blueprint for your API and website; you can register a before_request per blueprint and it'll be applied to the views for that blueprint only. Use per-view decorators rather than...

After long discussion I think tests should be smth like this (it is not tested :) ) require 'rails_helper' RSpec.describe ActivitiesController, :type => :controller do describe "GET index" do before(:each) do @activity = FactoryGirl.create(:activity) end context 'when user is logged' do before(:each) do session[:current_user] = @activity.user_id end it "shows all...

The best approach is to let the user logs in automatically when the email is confirmed, if the user confirms the account creation then when you find that user is valid then you may log in that user using something like: // $user = Get the user object Auth::login($user); Also...

By throwing exceptions you do exactly that. Nothing else necessary: throw new ForbiddenException(); or throw new NotFoundException(); etc. That is a clean way to bail early. The error/exception handler will automatically format it in the necessary output format (html, json, xml, ...) for you and will send the right headers...

You might want to try using before_action instead of before_filter. edit: as paul richter mentioned in the comments... before_filter will still work. But be aware that Rails is discouraging the use of before_filter and suggesting developers to use before_action instead. source: Ruby on Rails 4.2 Release Notes...

You can set the beforeFilter, like this: class ContentController extends BaseController { function __construct() { // this function will run before every action in the controller $this->beforeFilter(function() { // this will make the variable $myvar available in your view $this->layout->with('myvar', 'some-data'); }); } ... ...

The container parameters rule is that: You can only set a parameter before the container is compiled How to remedy the problem depends on your needs with the premise that the container is not thought to have dynamic parameters. create you custom dynamic "options" service and inject it in other...

Found it on Rails Guides: http://guides.rubyonrails.org/active_record_callbacks.html#conditional-callbacks Turns out a Proc isn't always required for it to work. the :if and :unless options, which can take a symbol, a string, a Proc or an Array. So in your case you could probably get away with before_action :check_stuff, if: "Rails.env.production?" Finding things...