Silly question about console and controllers

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?

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

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.

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 :slight_smile:

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 ) on Rails ( http://www.railsfrance.org
)

(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