librelist archives

« back to archive

Mounting Nesta at path and static theme assets

Mounting Nesta at path and static theme assets

From:
Michael Nosal
Date:
2012-06-25 @ 18:28
I'm struggling with serving static assets in my theme for nesta mounted at a path.

I'm using Rails 3.2.2, and have in my routes.rb file:
mount Nesta::App.new, :at => '/help'

Under my rails application directory, I've got nesta at:
app/help

which has 
app/help/config
app/help/content 
app/help/themes

I've got my theme installed in 
app/help/themes/mytheme

My theme's static assets are in:
app/help/themes/mytheme/public/mytheme/css 
app/help/themes/mytheme/public/mytheme/images

I've tried setting Rack::Static in my theme's app.rb file:
   
 use Rack::Static, :urls => ["/mytheme"], :root => "themes/mytheme/public"

but I can't get the static assets served. I can get to my content files 
just fine (/help/intro works correctly)

What's the correct way to get to static assets within a theme when nesta 
is mounted at a path?

--Mike



Re: [nesta] Mounting Nesta at path and static theme assets

From:
Graham Ashton
Date:
2012-06-25 @ 20:33
On 25 Jun 2012, at 19:28, Michael Nosal wrote:

> I'm struggling with serving static assets in my theme for nesta mounted 
at a path.
> 
> I'm using Rails 3.2.2, and have in my routes.rb file:
> mount Nesta::App.new, :at => '/help'

It's a long time since I've tried that myself, and I can't remember how 
assets behaved when mounted under Rack like that. Rack::Static ought to be
able to do it, but you might need to drop a debug statement into the 
Rack::Static code to see what it thinks the path ought to resolve to.

> Under my rails application directory, I've got nesta at:
> app/help
> 
> which has 
> app/help/config
> app/help/content 
> app/help/themes

When I'm using Nesta with a Rails app I share the Haml and Sass with the 
Rails app itself, by creating a slim controller to handle all the Nesta 
requests. The controller replaces the Sinatra actions that come with with 
Nesta. It works great (I can't take credit for the approach; it was Wynn's
idea).

I'm planning on extracting the logic from The Agile Planner site and 
releasing it as a gem. I'm not sure whether it'll be a generator to create
the controller for you, or a Rails engine that will have a controller 
embedded within it.

I need to re-use it in another Rails app myself this week, and may push an
alpha version to GitHub if it goes well. Let me know if you'd like to know
as soon as I've got something you could try (i.e. before I've had a chance
to test/document it significantly, which could take me a while).

> use Rack::Static, :urls => ["/mytheme"], :root => "themes/mytheme/public"

That looks good; maybe Rack is sticking the wrong prefix on the front. 
`bundle open rack` and the debugger gem would help you check my 
hypothesis.

--
Graham Ashton
Founder, The Agile Planner
http://theagileplanner.com | @agileplanner | @grahamashton


Re: [nesta] Mounting Nesta at path and static theme assets

From:
Michael Nosal
Date:
2012-06-27 @ 15:47
On Jun 25, 2012, at 4:33 PM, Graham Ashton wrote:

> On 25 Jun 2012, at 19:28, Michael Nosal wrote:
> 
>> I'm struggling with serving static assets in my theme for nesta mounted
at a path.
>> 
>> I'm using Rails 3.2.2, and have in my routes.rb file:
>> mount Nesta::App.new, :at => '/help'
> 
> 
>> use Rack::Static, :urls => ["/mytheme"], :root => "themes/mytheme/public"
> 
> That looks good; maybe Rack is sticking the wrong prefix on the front. 
`bundle open rack` and the debugger gem would help you check my 
hypothesis.

Simple solution, made obvious in two minutes looking at the rack gem:

use Rack::Static, :urls => ["/mytheme"], :root => "app/help/themes/mytheme/public"

I just needed to specify the file path that corresponds to the location 
where nesta is mounted in my Rails app. Everything's working fine now.

Thanks,
Mike