Writing extensions - custom (non-scaffold) views

I’m currently writing my first proper extension and am having problems
with custom views for the admin tab. I’m not using scaffold since the
extension isn’t model-based.

I noticed a few things that struck me as awkward but that I could work
around, including:

  • not being able to use filters in my controllers (they are ignored)

  • having to place my views in /app/views/admin/(extension_name) rather
    than just /app/views/admin

Something I’m not getting to work is passing locals to the view or
using references to instance variables. In all cases, I have a nil
object rather than a reference to the objects the controller sees /
instantiates.

Is this a known problem?

Regards,

Jan

Jan,

First, if your controller is public-facing (and not an admin tool), put
this line at the top to disable the login requirement:

no_login_required

Second, your views should correspond to the controller name, not the
extension name, unless of course they happened to be named the same
thing. So if your controller is Admin::FooController, your view path
should be app/views/admin/foo.

Third, in most cases, you should be passing objects as instance
variables to views, not locals, although there should be nothing to stop
you from explicitly rendering the view with locals.

Sean

Sean,

Thanks for the quick response, I was somehow expecting views to be
“nested” inside Radiant (for a reason I fail to recall now), but on
second sight app/views/admin/ is actually a straight-forward
and logical path for the views.

Now that the view works without a render hack, I can reference instance
variables in the view without problems.

One thing I noticed is that there isn’t a flash[:notice] display when
redirecting to the main admin page. But otherwise, all is well!

Jan

On Thu, 03 Jan 2008 08:33:40 -0600

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