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...
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...
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
...
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...
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...
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...
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 ...
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...
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
...
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 ...
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)
...
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 ...
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...
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....
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...
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...
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...
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 ...
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...
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?
...