before-filter

in Rails : Retreive user input from a form that isn't associated with a Model, use the result within the controller.

Here's a simplified version of what I'm trying to do : Before any other actions are performed, present the user with a form to retrieve a string. Input the string, and then redirect to the default controller action (e.g. index). The string only needs to exist, no other validations are necessary. The string must be available (as an ins...

before_filter with dynamic information

Hi I am trying to add a filter to a controller that is based on a certain role (using role_requirement) and then on the company_id that each user has. So basically I need something like this: require_role "company" ** This is working fine before_filter :company_required def company_required unless current_user.company_id == Compan...

rails: put and interruption in before filter

I want a before filter like "must_have_permission_to_write" that when called if user hasn't permission to write renders a message saying "you can't do that!" and return. Problem is I'm getting "can only render or redirect once per action" of course... how can I stop the execution in the before filter? thanks ...

How do you prevent database changes inside a Rails ActiveRecord before_create filter from getting rolled back when it returns false?

I've added a before_create filter to one of my Rails ActiveRecord models and inside that filter I'm doing some database updates. Sometimes I return false from the filter to prevent the creation of the target model, but that is causing all the other database changes I made (while inside the filter) to get rolled back. How can I preven...

should I limit attempts to login rails?

I'm thinking about building a login system for Ruby on Rails, much like this one http://visionmasterdesigns.com/tutorial-create-a-login-system-in-ruby-on-rails/ In terms of security, should I limit the attempts a user can have to login if they get their username wrong? Also,The basic steps of logins seem to be: authenticating userna...

RSpec in Rails: How to skip a before_filter?

Hello everyone, I am trying to test my controller and maintain separation of concerns. The first concern is "Who is able to execute which action?" I am using authlogic for authentication and be9's acl9 for authorization. But this should not matter, all my authorization concerns are handled in a before_filter. I am testing such a befor...

Error using private or protected methods in subclasses of ApplicationController

I have a filter shared between some controllers, wich is primarily declared as private in ApplicationController. This method sets find and pagination conditions for controllers. class ApplicationController < ActionController::Base ... protected # or private # Define parametros de busca def set_find_opts(klass) @filter ...

Skip before_filter in Rails

Names and objects have been simplified for clarity's sake. The basic concept reamins the same. I have three controllers: dog, cat, and horse. These controllers all inherit from the controller animal. In the controller animal, I have a before filter that authenticates a user as such: before_filter :authenticate def authenticate authe...

Rails: how to prevent links from being clicked while swf flash file is displayed

Hi everybody, I'm looking for a good way on preventing links in my rails app having any effect while a swf file is active... Can I do this with a before_filter? Or do I need javascript? Markus ...

Rails before_filter and action identification

Hi all, I want to write a before_filter in my controller to identify the action which will execute next. This is for authorization purposes (this is somewhat like role_requirement plugin do..) Ex: if a user types this url http://localhost:3000/users, default it goes to users/index action. And in my users controller i'm having a before ...

rspec + remarkable + before_filter

How do I test before_filter with rspec and remarkable. With only rspec I would do something like: controller.stub(:logged_in?).and_return(true) But with remarkable this results in: undefined local variable or method `controller' for #<Class:0x7f8f056ef3c0> (NameError) ...

Why is Rails before_filter called twice when the controller is subclassed?

I'm at Rails 2.3.5 and I have this problem: class BaseController < ApplicationController before_filter :foo, :only => [:index] end class ChildController < BaseController before_filter :foo, :only => [:index, :show, :other, :actions] end The problem is that on ChildController, the :foo before filter gets called twice. I've tried ...

before filter not working as expected

Hey guys I have a ruby on rails app with a before filter setup in my application controller to ensure only the owner can edit a document, but my permission check is always failing even when it shouldn't. Here is the code: def get_logged_in_user id = session[:user_id] unless id.nil? @current_user = User.find(id) end end def re...

In Sinatra, best way to serve iPhone layout vs. normal layout?

I'm writing a Sinatra app which needs to render different layouts based on whether the user is using an iPhone or a regular browser. I can detect the browser type using Rack-Mobile-Detect but I'm not sure of the best way to tell Sinatra which layout to use. Also, I have a feeling that how I choose to do this may also break page caching....

Automatic User Authentication Framework for Controllers in ASP.NET MVC?

In rails I could do something like this to make sure a user is authenticated before accessing an action in the controller: before_filter :checked_logged_in, :only => [:edit, :update] I was wondering if ASP.NET MVC had something similar or if there was a framework out there that could essentially do something like the following: For c...

How do I implement a before_filter callback in javascript?

Say I got this singleton object with some public methods and one private method: var QuestionFactory = (function() { // private method function google_it_first() { ... } // public methods return { ask_a_stupid_question: function() { ... }, ask_a_relatively_non_stupid_question: function() { ... }, ask_a_difficult_q...

How to skip before filters for json/xml requests in rails

I found a way to skip before filters based on the format, as seen below, but I'm wondering if there is a better way since this clutters things and isn't very DRY. before_filter do |controller| :current_cart unless controller.request.format.js? end If I don't do this, json requests fail because the current_cart method, and other meth...

Testing before_filter gets called in action

How would one test that when an action in controller is being accessed, that controller's before_filter will be executed? The before_filter is tested in separate example group so that there's no need to duplicate the tests for all actions that depend on the before_filter. If I have controller.should_receive(:my_before_filter) in my ...

Ruby on Rails, before_filter and prepend_before_filter ordering is?

In the following example, before_filter :foo before_filter :bar before_filter :wah prepend_before_filter :heehee prepend_before_filter :haha so then the execution orders will be: haha, heehee, foo, bar, wah? <-- note that haha is actually before heehee And is there a reason not to list haha and heehee first in the first place bu...

How to set a before_filter for every controller bar one?

In Ruby on Rails, I would like to add a before_filter to every controller except for one. Currently I have in ApplicationController: before_filter :authenticate Is there a way to apply this rule inside ApplicationController rather than adding before_filter :authenticate in every controller except the public controller? ...