before-filter

How can I dynamically set a parameter in Symfony2?

独自空忆成欢 提交于 2019-12-22 03:55:12
问题 I'm trying to dynamically set a parameter in Symfony2 (that I cannot statically set in my parameters.yml file). My approach is to use an EventListener : namespace Acme\AcmeBundle\EventListener; use Symfony\Component\DependencyInjection\Container; class AcmeListener { private $container; public function __construct(Container $container) { $this->container = $container; } public function onKernelRequest() { // Dynamically fetch $bar $bar = fetch('foobar'); // Set parameter $this->container-

Rails set layout from within a before_filter method

可紊 提交于 2019-12-18 12:49:33
问题 Is it possible to reset a default layout from within a before_filter method in Rails 3? I have the following as my contacts_controller.rb : class ContactsController < ApplicationController before_filter :admin_required, :only => [:index, :show] def show @contact = Contact.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @contact } end end [...] end And the following in my application_controller.rb class ApplicationController < ActionController:

How to prevent Symfony profiler from accessing or executing a listener

蓝咒 提交于 2019-12-13 01:28:01
问题 My user has countTasks property, with corresponding setter and getter: class User implements UserInterface, \Serializable { /** * @var integer */ private $countTasks; } I want this property to be always shown in the application's navigation bar (the "14" number in red): Obviously, this property should be set for every controller. (Actually, only for every that deals with rendering the navigation bar, but that's not the case here). So the application should count tasks for the currently logged

Hidden instance variables in before_filter method

≡放荡痞女 提交于 2019-12-11 10:12:02
问题 Is it a good practice to hide instance variable initialization in private methods? For example, I have a user controller with some actions: class UsersController < ApplicationController before_filter :get_user, only: [:show, :edit, :update, :destroy] before_filter :set_user, only: [:new, :create] def index @users = User.all end def show end def new end def edit end def create if @user.save redirect_to @user, notice: 'User was successfully created.' else render action: 'new' end end def update

Can't get skip_before_filter to work with ActiveAdmin in Rails

此生再无相见时 提交于 2019-12-11 09:26:41
问题 I am using the devise gem for authentication and have the following before_filter in my ApplicationController: before_filter :require_login def require_login unless user_signed_in? || params[:controller] == 'devise/sessions' flash[:error] = "You must be logged in to access that page." redirect_to new_user_session_path end end I have recently implemented the ActiveAdmin gem and am trying to get skip_before_filter to work for ActiveAdmin, so that I can access ActiveAdmin. I have attempted the

Ignore URI(request.referer).path for previous URL when visiting directly to a page

放肆的年华 提交于 2019-12-10 18:54:06
问题 I'm trying to save the previous URL in a session, I currently have this code: after_filter "save_my_previous_url", only: [:renderForm, :renderQuote] def save_my_previous_url if URI(request.referer).path session[:my_previouse_url] = URI(request.referer).path else session[:my_previouse_url] = URI(request.referer).path end end It works when you go from a page, to the form, then to the thank you page, but if you go straight to a form directly instead of clicking a link, I get this error: bad

Multiple before_filter statements for correct_user and admin

家住魔仙堡 提交于 2019-12-10 13:19:37
问题 I have a Group resource that I'm trying to set up with proper authorizations. The authorization logic I'm trying to implement is this: Only group members should be able to view their group. An admin can view any group, as well as take other actions. I'm attempting to do this with the following before_filter statements in the group controller: before_filter :signed_in_user before_filter :correct_user, only: :show before_filter :admin_user, only: [:show, :index, :edit, :update, :destroy]

Multiple before_filter statements for correct_user and admin

冷暖自知 提交于 2019-12-08 22:17:43
问题 I have a Group resource that I'm trying to set up with proper authorizations. The authorization logic I'm trying to implement is this: Only group members should be able to view their group. An admin can view any group, as well as take other actions. I'm attempting to do this with the following before_filter statements in the group controller: before_filter :signed_in_user before_filter :correct_user, only: :show before_filter :admin_user, only: [:show, :index, :edit, :update, :destroy]

before_filter with exception for current user

我们两清 提交于 2019-12-08 07:27:27
I have this current before filter in my users_controller before_filter :authenticate_usergroup, :except => [:edit, :update, :show] It works great for just allowing a user to edit their information but not being able to see all the users, but i'v found that by just changing their 'id' in the url they could also edit other users information. How can i only allow :edit, :show and :update functions to the current user for their own record. i have this method in my application_controller to be able to access the current user def current_user return unless session[:user_id] @current_user ||= User

Again: CSS, UL/OL: Incorrect indent with custom counter

自作多情 提交于 2019-12-08 02:25:59
问题 I described my original problem in this thread. In short, when using custom counters in ULs, the text indentation broke. Marc Audet proposed a very elegant solution which I implemented in our code. Now - not surprising - this does not work if the list is supposed to float around images :-( You can see the problem here: http://cssdesk.com/eEvwn The numbers are lying on top of the image. Again: no surprise, they are absolutely positioned after all. So. Is there a way to fix this, or do I have