Class def error when serving "stand-alone" rhtml files

I’m attempting to set up a rails app so that I can add rhtml files
without having to create controllers for each one. I want a simple
solution to serving static-like rhtml files as well as those with a
little logic. The solution I found is this one:

I added the following controller

static_controller.rb
#####################
class StaticController < ApplicationController
end

I then created a folder named static in my views folder. All seemed
fine(it worked) until I attempted to create a class in my rhtml code and
the following error was thrown:

compile error
script/…/config/…/app/views/static/imageMediation.rhtml:12: class
definition in method body

I’m a bit of a noob if you can’t tell. Any help would be appreciated.
Best

the whole point of the controller is to interact between your views and
your
models. This may be why your view is giving you a hard time. If you’re
serving out pages that don’t interact with the database at all, this is
a
good method, but as soon as you want to access a class, you should do
that
through the controller. I believe that when you don’t declare the
action in
the controller, you bypass the controller. That might have something to
do
with why you can’t access any models.

Mike W. wrote:

the whole point of the controller is to interact between your views and
your
models. This may be why your view is giving you a hard time. If you’re
serving out pages that don’t interact with the database at all, this is
a
good method, but as soon as you want to access a class, you should do
that
through the controller. I believe that when you don’t declare the
action in
the controller, you bypass the controller. That might have something to
do
with why you can’t access any models.

Right, I’m not trying to access the DB. The class is defined within the
rhtml file like this for instance:

<%
class MyClass
end
%>

blah

I get the error mentioned even if I don’t try to instantiate the class.

Is there some other(better) way to serve this sort of “one-shot” rhtml?

Thanks,
max

Hi –

On Tue, 1 Aug 2006, Max B. wrote:

the controller, you bypass the controller. That might have something to

blah

I get the error mentioned even if I don’t try to instantiate the class.

Is there some other(better) way to serve this sort of “one-shot” rhtml?

You should be able to circumvent the class definition in a method body
error by doing this:

Object.const_set(“MyClass”, Class.new { def x…; end })

But it does seem to cry out for a controller, or perhaps a class
definition in a file in /lib (or maybe a helper file).

David


http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack’s][ Web]log
http://www.manning.com/black => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.

unknown wrote:

Hi –

On Tue, 1 Aug 2006, Max B. wrote:

the controller, you bypass the controller. That might have something to

blah

I get the error mentioned even if I don’t try to instantiate the class.

Is there some other(better) way to serve this sort of “one-shot” rhtml?

You should be able to circumvent the class definition in a method body
error by doing this:

Object.const_set(“MyClass”, Class.new { def x…; end })

But it does seem to cry out for a controller, or perhaps a class
definition in a file in /lib (or maybe a helper file).

David


http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack’s][ Web]log
http://www.manning.com/black => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.

Thanks,
Sticking the classes in /lib works great.
Best,
Max

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs