Running commands from context of a view

From the command line, Is it possible to run a particular method in a
view from a specified controller.

e.g.

class MyController < ActionController
def test
end
end

view.rhtml
<%= link_to :action => :test %>

rendered_html

I’d like to be able to get that from the command line:
StudentProfilesController.new.send(‘link_to’, :action => test)

There are also a large number of other view commands i’d like to able to
call, so just grabbing out link_to doesn’t solve the issue

Cheers!

Sorry:
StudentProfilesController.new.send(‘link_to’, :action => test)

was supposed to be:
MyController.new.send(‘link_to’, :action => test)

i’ve tried:

a = MyController.new.view_class.new
a.send(‘initialize_current_url’)
vx = MyController.view_class.new(StudentProfilesController.view_root,
{}, a)
vx.link_to(:controller => ‘test’, :action => ‘test’)

but because half the internals are not initialized it doesn’t work.

Would trying to simulate the request and response parameters?
ActionController::Base
def process(request, response, method = :perform_action, *arguments)
#:nodoc:

On 12 Nov 2007, at 00:34, Alex M. wrote:

i’ve tried:

a = MyController.new.view_class.new
a.send(‘initialize_current_url’)
vx = MyController.view_class.new(StudentProfilesController.view_root,
{}, a)
vx.link_to(:controller => ‘test’, :action => ‘test’)

but because half the internals are not initialized it doesn’t work.

Have you seen this: http://snippets.dzone.com/posts/show/1799

Fred

Frederick C. wrote:

That allows you to run view helper methods… specifically I’d like to
be able to access view helper methods + route helpers edit_projects and
be able to use url_for and link_to.

I still haven’t worked out a way to do this… i’m wondering if i’ll need
to reimplement the process function of actioncontroller.base

On 13 Nov 2007, at 02:03, Alex M. wrote:

Frederick C. wrote:

That allows you to run view helper methods… specifically I’d like to
be able to access view helper methods + route helpers edit_projects
and
be able to use url_for and link_to.

link_to is a view helper as is one version of url_for. You just need
to figure out which modules to include (hint: search through the rails
code base for the functions you would like to be accessible)

Fred