I was afraid of that. :(
Can't believe nobody ever needed to use forms/helpers/etc in content
that is stored on database. Can't find anything at all. Guess I need
to start digging to figure out what's the difference between context
that haml engine gets during regular view renders and the one I'm
trying to feed it.
Thanks.
P.S. if anybody has any input on this it would be great.
On May 3, 6:49 pm, "Nathan Weizenbaum" <[EMAIL PROTECTED]> wrote:
> The thing is that a lot of the helpers assume a full Rails stack, with
> requests being dealt with by the controller and sent off to ActionView. It's
> a bit of a pain to emulate everything that happens there. That's why it
> wants the request object in the controller, for instance.
>
> The way to get around it is just to initialize everything the same way it's
> initialized by Rails. To figure out what this entails, you'll probably have
> to dig around in the Rails source code a little.
>
> - Nathan
>
> On 5/3/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
> > Ah, you confused me with ActiveRecord::Base vs ActionView::Base
> > thing...
>
> > I think I'm making progress:
>
> > >> base = ActionView::Base.new('/app/views/content', {},
> > ContentController)
> > => #<ActionView::Base:0x22df37c @base_path="/app/views/content",
> > @controller=ContentController, @assigns_added=nil, @assigns={},
> > @logger=#<Logger:0x22c4e28 @level=0,
> > @default_formatter=#<Logger::Formatter:0x22c4c98
> > @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:
> > 0x22c4bf8 @dev=#<File:script/../config/../config/../log/
> > development.log>, @shift_size=1048576, @shift_age=0,
> > @filename="script/../config/../config/../log/development.log",
> > @mutex=#<Logger::LogDevice::LogDeviceMutex:0x22c4b08 @mon_owner=nil,
> > @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>>,
> > @formatter=nil>>
> > >> Haml::Engine.new('= link_to "blah", "/"').render(base)
> > => "<a href=\"/\">blah</a>\n"
>
> > Awesome!
>
> > But:
>
> > >> Haml::Engine.new('= image_tag "blah.gif"').render(base)
> > NoMethodError: undefined method `request' for ContentController:Class
> > from (haml):1
> > from ./script/../config/../config/../vendor/rails/actionpack/
> > lib/action_view/helpers/asset_tag_helper.rb:207:in
> > `compute_public_path'
>
> > Bah, Fixable if I comment that line out in that ActionView helper.
>
> > There are still problems though.
>
> > I can't use my own helper methods still:
> > >> Haml::Engine.new('= short_date Date.today').render(base)
> > NoMethodError: undefined method `short_date' for #<ActionView::Base:
> > 0x228672c>
>
> > And I can't use partials:
> > >> Haml::Engine.new('= render :partial => "test"').render(base)
> > NoMethodError: undefined method `controller_path' for Class:Class
>
> > Still missing something :(
>
> > Thanks so much
>
> > On May 3, 2:06 pm, Nathan Weizenbaum <[EMAIL PROTECTED]> wrote:
> > > The third argument to the ActionView::Base is an actual instance of a
> > > controller. You need it to do stuff like url_for and link_to in
> > ActionView.
>
> > > The way Rails works is to render templates (both Haml and ERB) in an
> > > ActionView instance, giving you access to all the handy helpers. You
> > > could do it in a model like User, but then you wouldn't have access to
> > > the helpers but would instead have access to the User's variables, which
> > > would be weird.
>
> > > - Nathan
>
> > > [EMAIL PROTECTED] wrote:
> > > > Hey Nathan,
>
> > > > Context thing definitely makes sense to me now. However I have
> > > > difficulty properly setting up that base variable.
>
> > > > So if I do
>
> > > >>> base = ActiveRecord::Base.new('app/views', {}, ContentController)
>
> > > > NameError: uninitialized constant ContentController
>
> > > > I have ContentController that is not tied to any model there.
> > > > Obviously I'm doing this completely wrong.
>
> > > > also
> > > > base = User.new doesn't really provide context that I'm looking for?
> > > > Different thing?
>
> > > > Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---