# Silly question about console and controllers

**URL:** <https://www.ruby-forum.com/t/silly-question-about-console-and-controllers/88931>\
**Category:** Rails\
**Created:** [March 15, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/silly-question-about-console-and-controllers/88931 "2007-03-15T18:12:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [March 15, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/silly-question-about-console-and-controllers/88931/1 "2007-03-15T18:12:11Z")

</div>

I’m a bit of a n00b, so my problem is more that I can’t figure out the  
last step from other posts.

I want to launch some controller methods in application.rb from a  
script, so I’m trying to use the console to help write it.

?\> require “app/controllers/application.rb”  
=\> true

> > ApplicationController.post\_render(:id =\> 119)  
> > NoMethodError: undefined method `post\_render’ for  
> > ApplicationController:Class  
> > from (irb):5

> > ApplicationController.instance\_methods  
> > =\> [“methods”, “web\_service\_object”,  
> > “render\_nothing”…“post\_render”,  
> > … “gem”, “transition”, “silence\_stream”]

What really silly thing am I doing wrong?

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [March 15, 2007, 6:24pm UTC](https://www.ruby-forum.com/t/silly-question-about-console-and-controllers/88931/2 "2007-03-15T18:24:01Z")

</div>

Hi Jonathan,

Jonathan D. wrote:

> I want to launch some controller methods in application.rb  
> \< from a script, so I’m trying to use the console to help write it.

> ?\> require “app/controllers/application.rb”  
> =\> true

It looks like you might be using irb rather than the console. irb is  
just  
Ruby. script/console loads your development (i.e., Rails) environment.

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [March 15, 2007, 7:57pm UTC](https://www.ruby-forum.com/t/silly-question-about-console-and-controllers/88931/3 "2007-03-15T19:57:23Z")

</div>

Bill W. wrote:

> Hi Jonathan,
> 
> Jonathan D. wrote:
> 
> > I want to launch some controller methods in application.rb  
> > \< from a script, so I’m trying to use the console to help write it.
> 
> > ?\> require “app/controllers/application.rb”  
> > =\> true
> 
> It looks like you might be using irb rather than the console. irb is  
> just  
> Ruby. script/console loads your development (i.e., Rails) environment.

I’m using whatever loads when, from the ruby root directory I run  
`script/console`

I’m using:  
#!/usr/bin/env ruby  
RAILS\_ENV = ‘development’  
require File.dirname( **FILE** ) + ‘/…/config/environment’

as the header to the final script (which appears to give me a very  
similar environment to the console)

The ‘require’ line does appear to be redundant though.

My methods are in instance\_methods, but not in methods, if that helps.

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [March 15, 2007, 7:58pm UTC](https://www.ruby-forum.com/t/silly-question-about-console-and-controllers/88931/4 "2007-03-15T19:58:13Z")

</div>

Jonathan :

> I want to launch some controller methods in application.rb  
> from a script, so I’m trying to use the console to help write it.
> 
> ?\> require “app/controllers/application.rb”  
> =\> true

you don’t have to require it in script/console.

> What really silly thing am I doing wrong?  
> #post\_render is an instance method and you’re invoking it  
> as a class method, so it doesn’t work 🙂

If you want to test your action in script/console, call it  
as if it were a browser :

app.get ‘my\_url’

(like app.get ‘article/show/2’ )

and inspect it :

app.response.body  
app.controller.params  
…

– Jean-François.

–  
Ruby ( [http://www.rubyfrance.org](http://www.rubyfrance.org) ) on Rails ( [http://www.railsfrance.org](http://www.railsfrance.org)  
)

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [March 15, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/silly-question-about-console-and-controllers/88931/5 "2007-03-15T20:27:23Z")

</div>

> (like app.get ‘article/show/2’ )
> 
> and inspect it :
> 
> app.response.body  
> app.controller.params  
> …

Is there another way to do it? I’m using .htaccess files to tie  
authentication to our LDAP servers and I just get 401s
