Displaying 20 results from an estimated 8000 matches similar to: "Silly question re: scoping of controller actions"
2005 Nov 03
9
[Idea] session-wide persistent variables
I was thinking about having instance variable stored and fetched from
session container automatically before calling an action and after the
action is finished. Using methodology of accessors it would look like:
class MyController < ActionController::Base
persistent_attr :person
def alfa
person = ''John Smith''
# render as usual view alfa.rhtml with anchor
2006 Apr 18
4
Mixin variables
I''ve created an access control module that I''m including in several
different controllers. Everything works fine, but I want to allow each
controller to override the default login page with something like this:
set_login_pages :secure => ''my_login''
In my module, I''ve set up the set_login_pages method like this:
def self.included(base)
2006 Jun 02
6
Set instance variable for all actions in the Controller
Can I set an application wide instance variable that is available for all
actions...and their views?
eg.
class ApplicationController < ActionController::Base
@current_user = User.find(session[:user_id])
end
and everywhere I can call @current_user.id and I can get that object? Even
down in the views?
I could not get this to work...
Thanks in advance,
Jeff
-------------- next part
2006 Jan 30
14
RoR admin system
I''m preety new at RoR (and programming), I tried a few tutorials, and
really like the RoR simplicity, but my knowledge of the framework still
isn''t very good (to be true, i understand the basics, but not everything
that''s in the tutorials).
But still I''d like to create a website which has:
- front end interface (with no edit functions)
- admin interface
2006 Aug 15
3
instance variables in layouts
There''s probably a simple answer to this simple problem, but I am trying
to figure out how to reference an instance variable within a layout. In
the controller, one method corresponds to a view of the same name. Those
instance variables in the method can be used in the corresponding view.
However, I want my instance variable to be accessible throughout all my
views, not just one,
2005 Dec 15
4
Acts_as_tree and routing
I''ve got an acts_as_tree structure which I want to be able to represent
in the URL, with one field identified as the url component. In other
words, if I''ve got this:
def self.up
create_table :nodes do |t|
t.column :parent_id, :integer
t.column :tag, :string
end
end
and
class Node < ActiveRecord::Base
acts_as_tree
end
and what I want the urls to be is something
2007 Mar 20
1
Passing Arguments to before_filter
I want to put a before_filter in application.rb, as follows:
before_filter :do_something, :except_controller => [:admin]
def do_something(options)
options.stringify_keys!
unless options[:except_controller].include?(controller_name)
# do something useful
end
end
Where I''m blocking is on how to get the ''options'' data in the do_something
method. I think I
2005 Dec 25
4
How to display a welcome page
Wow, I can''t believe that after a few weeks of playing around with Rails I
got stuck on something that seems like it should be really simple.
How do I display a default welcome page for visitors who are not logged in
and send logged in users to the appropriate controller. I am using the
login_engine and the user_engine.
The two methods I have seen looking at sample code are to stick a
2007 Oct 16
6
Failure trying to test ApplicationController
I''m trying to write some tests for the ApplicationController as shared
tests that can be run in all of my other controller tests, but am getting
a nil.rewrite error. Below is what I have...
describe AccountController do
it_should_behave_like ''Application controller''
end
describe ''Application controller'', :shared => true do
it
2006 Jan 19
4
Relationships... not the personal kind!
Hello all,
I''m very new to Rails and I love it so far. However, there are some
things that aren''t so clear to me.
Let''s say a blog post can have many comments, and a comment can only
belong to one post. A user can have many posts and many comments as
well. (this part makes perfect sense):
class Comment < ActiveRecord::Base
belongs_to :posting
belongs_to :user
2006 Jan 29
3
SHLG and lib dir
Slowly figuring out how to get my SaltedHashLoginGenerator stuff working. The wiki page
says to put "before_filter :login_required" in the user (my "user" is "member") controller
or in ApplicationController. However, wherever I put it I get NoMethodError.
The rest of the SHLG stuff seems to be working... or at least I could get to the signup
page, register, and
2006 Jan 08
3
Family Connection 1.1.2
== What is Family Connection? ==
Family Connection is an easy-to-setup online hub for your family that
includes a Family News section with Photos, and an Address Book.
For more information, visit http://familyconnect.rubyforge.org/
== Downloads ==
Latest:
svn checkout svn://rubyforge.org/var/svn/familyconnect/trunk
Version 1.1.2:
svn checkout
2006 Jan 23
5
Variable Scoping Problem
I am having some problems with variable scoping.
I need to be able to set a variable that is accessable by other methods
within the class (or instance) (i.e not global).
An example is 2 pages that change a class variable:
class AjtestController < ApplicationController
def initialize
@@variable = "init"
end
def show
@display = @@variable
@@variable = "change 1"
2006 Jul 26
5
Restricting before_filter to certain actions?
Can you restric before_filter to specific actions?
--
Posted via http://www.ruby-forum.com/.
2006 May 09
4
Ajax calls and characters encoding (accents)
Hello, my application controller defines
before_filter :set_charset
def set_charset
@headers["Content-Type"] = "text/html; charset=ISO-8859-1"
end
Everything is fine and accents are rendered correctly in the browser.
However, when I call a controller/action from Ajax (Prototype), the
charset is not taken in account and accents are garbage displayed (''?''
2006 Jun 07
2
Making an HTTP request to an external machine
During one of my controller actions I want to call an external machine
before I do anything. It''s not a real web service, more like a
REST-style thing where I''ll just be tweaking a servlet running on
another machine and sending it some data.
Does Rails give me anything to work with for doing that? I read the web
service stuff but it''s overkill for what I need. I
2006 Apr 29
3
Noob question... confused
If I have several controller actions which have this same line of code (or
more), how can I DRY up the line without running into complaints about
redirecting or rendering only once? If I put the line in another method in
my controller, won''t it think I''m redirecting?
I want to dry up lines like this: @listing = Listing.find(params[:id])
def customerview
@listing =
2006 Aug 02
12
Authenticate with an IP address : LoginGenerator
Is there a way to authenticate with an IP address? I''m using the
LoginGenerator, but would like to bypass the "before_filter
:login_required
" if a user is in a correct IP range...
Anyone know of a solution?
Thanks!
--
Posted via http://www.ruby-forum.com/.
2005 Dec 20
2
printing/logging during tests
Hi all,
I''m trying to output some info to see what''s happening in a controller
during functional tests.
Problem: ''print'' only works in the test code, but not in the production
code that''s being called by the tests.
Example:
In FooControllerTest:
def test_list
print "1: starting" <<----- WORKS FINE
get
2006 Feb 27
1
decode URL
Hi,
I have a URL with encoded characters, I want them to be decoded.
Is this possible in the routes.rb?
e.g. decoding the @params[category]
map.connect ''performances/:category'', :controller => ''performance'',
:action => ''list_performances''
regards,
J?rg