Displaying 20 results from an estimated 10000 matches similar to: "redirecto_to within helpers"
2006 May 16
2
before_filter and the application controller
Hi there,
I''m having a bit of an issue with my before_filter. I know that the filters
put in the application.rb controller are global for all the controllers. In
my application filter I''d like to allow access to the RSS feed method in a
''member'' controller and skip the login checks that the before_filters are
currently performing.
In my application my filters
2010 May 08
3
Count cases in a list
Hi everybody, I would like to count how many times names in list L,
nombreL, apear in list C, nombreC.
Can I improve the next program?
cuenta <- 0
topL <- length(nombreL)
topC <- length(nombreC)
for (i in 1:topL) {
for (j in 1:topC) {
k <-
grep(noquote(nombreL[i]),nombreC[j])
2006 Feb 13
1
hackish error handling
I''ve got a block of code that''s turning out.. well - just plain ugly.
So i know I must not be doing it the Ruby way.
The main problem I''m having is in dealing with handling errors - and
just not finding much Rails documentation that gives a deeper
understanding of how to handle errors in Rails (outside of several
docs on the catch-all''s)
the main method
2006 Apr 21
9
Yet another dry question..
One of these days I''ll figure this out, but in the meantime help me be a
better programmer by eliminating some excess code:
I''m trying to check to see if somebody trying to view/edit/update a
product is the owner. In my scaffold I have this code that works:
def edit
@owner = Product.find(params[:id].to_i)
if @owner.user_id == @user.id
@product =
2006 Jul 02
3
2 before_filters, only want one to render something
I have two before_filters for a few of my controllers. They are running
my own methods authorize and admin_authorize. authorize is called on
just about every action to make sure that a user is logged in.
admin_authorize is called on about 80% of the actions and is used to
make sure that a user is an administrator. If a user tries to access an
admin_authorize protected action without being
2008 Feb 22
7
Testing misc methods in ApplicationController
I''m already successfully testing before_filters in application_controller
courtesy of this blog post:
http://www.movesonrails.com/articles/2008/01/23/spec-ing-your-application-controller
However, i can;''t work out how to test the sort of method that is added to
application_controller so that all controllers can use it. It must be
something simple that i''m doing
2009 Apr 24
4
Undefined method "redirect_to" in before_filter
Code sample:
class SomeController < ApplicationController
before_filter do |c|
add_crumb "Blah", "/blah" #breadcrumbs plugin
redirect_to :controller => "foo", :action => "bar" unless c.send
(:has_package?)
end
# Rest of the controller...
private
def has_package?
# A bunch of logic work to check to make sure
# somebody''s session contains
2006 Apr 11
1
Double redirect
I have two before_filters for my application that both redirect. The
first checks whether there is an active session and if so, whether it
has timed out (a la the recipes book). This is run from
ApplicationController. The second filter is in use throughout most of
the app and checks to see whether the user has the correct credentials
to view the controller. This is run from individual
2007 Feb 14
2
prepend_before_filter
I''ve got a couple of before_filters that need to run in a specific order. One does a redirect_to if a session variable isn''t set. The other does a find which will fail if the session variable isn''t set. So they need to run in that order. But prepend_before_filter doesn''t seem to be working as advertised. Anybody got any insight? I''m still running
2007 Oct 26
2
Examples of writing controller specs that use authentication
Hello,
I''m working on specs for a controller that handles authentication
using the restful_authentication plugin. I''m trying to find a
resource (tutorial or examples, if possible) about the best way to go
about writing mocks and specs to make sure that things like my
before_filters are working correctly. Does anyone know of any good
resources for this?
Thanks,
Les
2006 Jul 18
6
before_filter chains and halting at an arbitrary filter
Hi--I''m trying to implement a 2-level authentication system, where I
have one before_filter which does general user authentication, and
another which does further authorization for a specific controller. I
have it set up as follows:
before_filter :authorize_level_2
prepend_before_filter :authorize_level_1
which causes authorize_level_1() to run, and then authorize_level_2().
2006 May 31
5
Sharing code between some controllers? Staying DRY
Hi,
I have four controllers: one for the store front and three for the
store admin. In each controller I have copied and pasted exactly the
same code. It is a method called redirect_to() to override Action
Controller''s redirect_to(). Copy and paste is bad. I can think of two
options but I don''t know how Rails will feel about them.
Option 1: Can I create an intermediate
2006 Aug 07
2
Ugggh..another recipes question
sorry, because it seems that I need more explanation on this Rails
Recipes authorization -
I finally got the code working but after using the login I get this
back from Rails-
Routing Error
No url can be generated for the hash {}
I''m guessing it''s coming from the redirect-
def login
if request.post?
session[:user] = User.authenticate(params[:first_name],
2006 Mar 24
6
login forms , redirect_to and ajax-scaffold problems
Hi,
I have a standard type authentication technique direct from AWDWR, so there is a
before_filter :authorize_employee, :except => :login in my employees_controller.rb
the authorize_employee is in application.rb
def authorize_employee
unless session[:employee_id]
flash[:notice] = "Please log in"
# save the URL the user requested so we can hop
2006 Jul 10
1
Redirects and keeping flash
My code that acts if a session has timed out looks like this:
reset_session
session[:expires_at] = nil
# TODO - This flash is never shown, because we redirect maybe?
flash[:error] = ''Your session has timed out, please login to
continue.''
# An attempt to make flash stick around, not working
flash.keep
redirect_to :controller => ''security'',
2008 Dec 03
2
Render and/or redirect were called multiple times in this action
I''m trying to add an application enabled/disabled flag in my
application.. This is my code.
[code=] # application.rb
...
before_filter :check_enabled_flag
private
def check_enabled_flag
application_flag = ApplicationFlag.find(:first)
if application_flag.application_enabled
redirect_to application_disabled_path and return
end
end[/code]
and for some reason
2006 Apr 21
1
Catch authentication result from a model in a controller
Im still following the authorization recipe from the book, now all works
fine but im getting trouble in how handle the model authorization
result, if the user and pass are correct, it goes to a welcome
screen(admin.rhtml) but if wrong the model prints a message in an ugly
exception like page "usr and pass not correct", i want to redirect the
user to the login
2006 Feb 21
5
Abstracting ownership verification out of Controller
Right now I have a controller for "events" that belong to a specific
user. I only want the creator to be able to edit or delete the event.
I''ve got the proper foreign keys set up.
I''ve finally arrived at the point where I can take baby steps with
code, but looks like my first steps are in flagrant violation of the
DRY principle.
Here''s what I have so far in
2007 Dec 03
8
automatic 'verify :xhr => true' for methods ending with _xhr
hey guys,
i am writing a couple of actions which are only used with an xhr. I
''protect'' them all against a direct access with the ''verify'' method in
the controller
verify :only => ..., :xhr => true
it would be cool if the system would automatically recognize the xhr
actions and protect them ... i want to postfix methods with ''_xhr'' and
2006 Jun 01
3
how can i redirect a person after a login
i built my own login system, but unfortunately, i am having problems
(ie, can''t really figure out how) to redirect a person back to the page
he was requesting before logging in...say, as the admin i want to edit a
certain message/logo, whatever, so i click on it, and i get redirected
to my login page. after the admin logs in, he gets redirected to the
homepage - i couldn''t