Displaying 20 results from an estimated 30000 matches similar to: "How to get dependent Model(s) from Controller"
2006 Jul 14
3
Accessing the Model class from Controller
Hi,
I wonder if there''s an easy way to access the associated Model class
from its Controller. Something that would allow me to write snippets
like the following:
class PeopleController < ApplicationController
def some_method
person_model_class =
self.some_method_to_retrieve_the_person_model_class()
end
end
Cheers,
Marco
--
Posted via
2006 Apr 03
1
Best way to set custom Controller options
Hi All!
I''m searching a good way to set some options in my Controllers; I tried
defining a custom function, ie:
class PeopleController < ApplicationController
set_my_actions :action1, :action2
end
class ApplicationController
def self.set_my_actions(*args)
@@my_actions = args
end
end
But ''@@my_actions'' sets the class variable to _every_
2006 Jul 09
1
Accessing the name of a controller''s module?
If I''m redirecting to a log in page, and saving the controller and
action name in the session hash, how do I also save the controller
module?
After the log in is completed, I can''t redirect back to the originally
directed page because it''s in a different controller module. For the
controller action name I can use the ActionController instance method
controller_name(),
2005 May 22
1
ActiveRecord: can not connect to mysql
Hi
I would like to write my first application with Active
Record:
this is my database table:
id PRIMAREY KEY auto_increment
german_name varchar(50)
english_name varchar(50) |
wingspan
this is my code:
=======================
#!/usr/local/bin/ruby -w
require ''rubygems''
require_gem ''activerecord'', ">= 1.10.1"
2005 Aug 23
0
Fixtures: pluraly bitten
With my functional tests (on PgSQL) I get strange errors like this
1) Error:
test_create(AufgabeControllerTest):
ActiveRecord::StatementInvalid: ERROR: duplicate key violates unique
constraint "aufgaben_pkey"
Tracking this down, I found that sequences are only reset for some of
the tables I''m using. The reason? Inconsistent singularization.
I won''t go so far as
2007 Apr 11
10
DRYer controller specs
So, I''ve been following the recommendations for controller specs here:
http://blog.davidchelimsky.net/articles/2006/11/09/tutorial-rspec-stubs-and-mocks
Most notably: a single expectation per specify block; the setup block
contains only stubs; mock expectations each get their own specify
block. (I''m still using 0.8, so I haven''t gotten the describe/it
goodness yet.)
I
2007 Feb 15
4
defining context(s) dynamically
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Q. Why does code which defines a context work in the
2007 Oct 07
0
Is there a way to use the rescue_action defined in a controller in the controller''s specs?
Heyho,
I start to discover RSpec but it seems that just on my second day I
ran into some strange trouble with the rescue_action of my
controllers. Just like in Rails 2.0 where there is a
rescue_from Exception, :with => :foo_method
thing to rescue exception thrown in actions in the production
environment, I did a little helper that rescues my action exceptions
with a defined class.
For
2006 Jan 28
13
What''s the verb form of id?
Random question:
I''ve written a method for the String class that turns an arbitrary
line of text in to an identifier, e.g.:
"My, what a beautiful day!"
=> "my_what_a_beautiful_day"
"(anb*#NF(AMNV"
=> "anb_NF_AMNV"
We''ve got all these great names already like underscore, classify,
titleize and things like that. I''d
2007 Mar 12
1
Can't follow redirects outside current controller - but it's the same controller
Running a functional test on FooController that does
''follow_redirect'', I get ''Can''t follow redirects outside current
controller (from "foo" to "foo"). On further investigation, it turns
out that :foo != ''foo'' around line 401 of actionpack/lib/
action_controller/test_process.rb. Changing the line:
if redirected_controller
2007 Jun 27
2
Controller specs not shareable?
Hi
I just wondered if there was a reason why Rails controller specs are
not shareable? eg
describe "All XHR POSTs to /gap/calculate_quote", :shared => true do
controller_name :gap
# ...
end
describe "XHR POST /gap/calculate_quote with valid details" do
it_should_behave_like "All XHR POSTs to /gap/calculate_quote"
# ...
end
blows up with
2009 Jan 14
0
Edit method problem with a plural-named model
Hi, I recently made a model called ''news''. I realize that it''s plural
and was gonna cause some problems, but I got the routing all down fine
with:
map.resources :news, :singular => :news_article
everything works fine except the EDIT method. it gives me this error:
You have a nil object when you didn''t expect it!
The error occurred while evaluating
2005 Apr 06
3
NameError in <controller not set>#<action not set>
I can''t figure out why I''m getting the following error. There''s
nothing wrong in my communities_controller file. And the helper for
communties exists.
Any ideas?
Thanks,
Joe
NameError in <controller not set>#<action not set>
uninitialized constant CommunitiesHelper
app/controllers/communities_controller.rb:1
script/server:48
Show framework trace
2007 May 08
4
help with rspec''ing controller
Hi,
I''m a rspec newbie. I''m having trouble with rspec''ing a simple
controller to Create a record.
I''ve tried a couple of approaches and still get errors:
Mock ''remedy'' expected :save! with (any args) once, but received it 0
times
-or-
Mock ''Remedy'' received unexpected message :save with (no args).
Here are my two
2007 Jul 24
4
spec''ing helpers that use controller
Hi all,
I''m in the process of creating rspecs for my helpers. One of the
helpers in app/helpers/application_helper.rb looks like this:
def page_name
@page_name || "Define @page_name in
#{controller.controller_name}::#{controller.action_name}"
end
The rspec is simply:
it "should something" do
page_name
end
2006 Jul 22
4
Accessing the controller name in your views?
I need to know what controller and action the user is currently in
to do various things in my layouts/application.rhtml file. Isn''t
there is a better way than:
<% if params[:controller] == "whatever" && params[:action] ==
"whatever" %>some html<% end %>
I know in the controllers you can just use controller_name, but that
is not provided
2007 Apr 20
1
getting controller specs to work on edge
I''m using edge spec, edge rspec_on_rails, edge rails. I just switched to
edge and ran the translator tool and I''m trying to get everything to pass
again. One of my issues is getting render back up and working for my
controller specs, here''s an example:
describe "Requesting /users using GET" do
controller_name :users
setup do
@user = mock_model(User)
2008 Apr 29
1
Spec''ing controller macros
Hi,
(This is my first post after months of appreciative lurking...)
I''m trying to spec the following conditional controller macro:
class ApplicationController < ActionController::Base
# turn off session management for robots
session :off, :if => lambda {|req| req.user_agent =~ /(Google|Slurp)/i }
# ...
end
My current attempt seems to be quite unsuccessful:
1) when I
2008 Dec 07
2
Strange 500 Error with namespace::controller#action appearing in reload only
The portion of the log linked below is two requests directly out of
the log file for the same action. The first request was from me
putting the address in the browser directly (but can be duplicated by
linking to the url anywhere in the app). When I reload the browser on
this url, I get a strange error. To the user, the action appears to
load fine, but I''m getting a 500 error in the log
2006 Nov 08
1
controller.session not same as session?
> context "A user logging out" do
> fixtures :users
> controller_name :account
>
> setup do
> login_as :quentin
> users(:quentin).remember_me
> request.cookies["auth_token"] = cookie_for(:quentin)
> end
>
> def logout
> get :logout
> end
>
> specify "should unset :user in session" do