Forum: Ruby on Rails RCSS problems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
77961c972c437d6801714f45c3f2cc3c?d=identicon&s=25 Raphael Schmid (rapha)
on 2006-03-04 00:15
Hi List!

Following http://rcss.rubyforge.org/files/README.html, I'm trying to get
RCSS to work with Rails. The rcss command itself works fine, but when
trying to access http://localhost:3000/rcss/test.css I always get
"Unknown action - No action responded to test.css", which I don't
understand since the route and controller are in place.

Anyway, hopefully this is just a newbie's lacking knowledge of Rails :-)

Whatever pointers you might have would be greatly appreciated...

Best regards,
Raphael Schmid
77961c972c437d6801714f45c3f2cc3c?d=identicon&s=25 Raphael Schmid (rapha)
on 2006-03-04 19:48
Hi again,

after some fiddling around with initial help from rainmkr on IRC, I've
come to the conclusion that there must be something wrong with the
render() call in the RcssController as shown at
http://rcss.rubyforge.org/files/README.html.

The type is set to 'rcss', but the README doesn't talk about any piece
of code that'd tell Rails to process *.rcss files with the /usr/bin/rcss
command. Does anybody know if that code exists anywhere, or could give
me a pointer towards creation of such code?

Thanks and best regards,
                    Raphael Schmid
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-05 12:48
(Received via mailing list)
On 04/03/06, Raphael Schmid <raphael@schwarzschmid.de> wrote:
> me a pointer towards creation of such code?
Binding the Scc processer to Rcss file type is done automatically when
you require 'rcss' in environment.rb.

The response you are getting "Unknown action - No action responded to
test.css" suggests that your routes.rb is not set-up properly. Could
you provide your routes.rb? It would help to find the problem.
77961c972c437d6801714f45c3f2cc3c?d=identicon&s=25 Raphael Schmid (rapha)
on 2006-03-05 15:41
Czezch Łukasz,

thanks for your reply! My complete routes.rb looks like this right now:

ActionController::Routing::Routes.draw do |map|
  map.connect '', :controller => "login"
#  map.connect 'stylesheets/:rcss', :controller => 'rcss'
  map.connect ':controller/service.wsdl', :action => 'wsdl'
  map.connect ':controller/:action/:id'
#  map.connect 'rcss/:rcss', :controller => 'rcss'
  map.rcss 'rcss/:rcss', :controller => 'rcss'
#  map.connect 'stylesheets/:rcss', :controller => 'rcss', :action =>
'render_rcss'
end

As you can see, I've been playing around with the routes quite a bit,
to no avail. Tell me if there is anything else that can be done.

Best regards,
          Raphael
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-05 16:17
(Received via mailing list)
On 05/03/06, Raphael Schmid <raphael@schwarzschmid.de> wrote:
> Czezch Łukasz,
> ActionController::Routing::Routes.draw do |map|
>   map.connect '', :controller => "login"
> #  map.connect 'stylesheets/:rcss', :controller => 'rcss'
>   map.connect ':controller/service.wsdl', :action => 'wsdl'

----

>   map.connect ':controller/:action/:id'
> #  map.connect 'rcss/:rcss', :controller => 'rcss'
>   map.rcss 'rcss/:rcss', :controller => 'rcss'
> #  map.connect 'stylesheets/:rcss', :controller => 'rcss', :action =>
> 'render_rcss'

---

> As you can see, I've been playing around with the routes quite a bit,
> to no avail. Tell me if there is anything else that can be done.

I have marked important part. The line

map.connect ':controller/:action/:id'

describes the most generic route. It caches everything what has not
been caught yet. If you put another rule below this line it will not
be reached at all. My suggestion is to use following setup and try
again:

ActionController::Routing::Routes.draw do |map|
 map.connect '', :controller => "login"
 map.connect 'rcss/:rcss', :controller => 'rcss', :action =>
'render_rcss'
 map.connect ':controller/service.wsdl', :action => 'wsdl'
 map.connect ':controller/:action/:id'
 map.rcss 'rcss/:rcss', :controller => 'rcss'
end

As a sidenote: in Rcss subversion repository you will find
engine-based version or Rcss. It is tested and working but it lacks
documentation. Contact me if you are interested.
77961c972c437d6801714f45c3f2cc3c?d=identicon&s=25 Raphael Schmid (rapha)
on 2006-03-05 21:43
Hi,

> ActionController::Routing::Routes.draw do |map|
>  map.connect '', :controller => "login"
>  map.connect 'rcss/:rcss', :controller => 'rcss', :action =>
> 'render_rcss'
>  map.connect ':controller/service.wsdl', :action => 'wsdl'
>  map.connect ':controller/:action/:id'
>  map.rcss 'rcss/:rcss', :controller => 'rcss'
> end

I put that into my routes.rb. Now it says it couldn't find the
template ``test.rhtml''. For reference, this is what my controller
looks like:

class RcssController < ApplicationController
  def render_rcss
    if params[:rcss] =~ /\.css$/
      template = $`
    else
      template = params[:rcss]
    end

    render :action => template, :type => 'rcss', :layout => false
  end
end

> As a sidenote: in Rcss subversion repository you will find
> engine-based version or Rcss. It is tested and working but it lacks
> documentation. Contact me if you are interested.

Yes, found that one already. If possible, I'd like to try and not get
any Engine whatsoever into my application. Just doesn't feel right.
A plugin, like Markaby, would be great though :-) (is there something
about creating plugins -- I'd give it a shot)

Thanks and best regards,
Raphael
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-06 12:17
(Received via mailing list)
On 05/03/06, Raphael Schmid <raphael@schwarzschmid.de> wrote:
> Hi,
> I put that into my routes.rb. Now it says it couldn't find the
> template ``test.rhtml''.

Could you confirm that rcss gem is installed and that you put a line

require 'rcss'

in your environment.rb (preferably at the bottom)?

I just followed instructions with a clean application and it works. I
would suggest you to do the same - it will help troubleshoot.

> Yes, found that one already. If possible, I'd like to try and not get
> any Engine whatsoever into my application. Just doesn't feel right.
> A plugin, like Markaby, would be great though :-) (is there something
> about creating plugins -- I'd give it a shot)

Actually a simple plugin would just need a one line init.rb:

require "rcss"

:)
77961c972c437d6801714f45c3f2cc3c?d=identicon&s=25 Raphael Schmid (rapha)
on 2006-03-06 15:26
> Could you confirm that rcss gem is installed and that you put a line

Acknowledged.

> require 'rcss'
> in your environment.rb (preferably at the bottom)?

Acknowledged.

> I just followed instructions with a clean application and it works. I
> would suggest you to do the same - it will help troubleshoot.

Here we go:

---< snip >---
rapha@proactivity~ $ rails Test
...
rapha@proactivity~ $ cd Test
rapha@proactivity~/Test $ script/generate controller rcss
...

rapha@proactivity~/Test $ vi app/views/rcss/test.rcss
[Adding RCSS content according to README]

rapha@proactivity~/Test $ script/console
Loading development environment.
>> require 'rcss'
=> true [Looks like the gem is installed correctly...]
>> exit

rapha@proactivity:~/Test$ vi config/environment.rb
[Adding "require 'rcss'" at bottom]

rapha@proactivity:~/Test$ vi app/controllers/rcss_controller.rb
[Adding render_rcss method according to README]

rapha@proactivity:~/Test$ vi config/routes.rb
[Adding routes as per your former email]

rapha@proactivity:~/Test$ script/server
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-03-06 15:18:36] INFO  WEBrick 1.3.1
[2006-03-06 15:18:36] INFO  ruby 1.8.3 (2005-06-23) [i486-linux]
[2006-03-06 15:18:37] INFO  WEBrick::HTTPServer#start: pid=31018
port=3000

rapha@proactivity:~$ links http://localhost:3000/rcss/test.css
Action Controller: Exception caught
Template is missing
Missing template ./script/../config/../app/views//rcss/test.rhtml

rapha@proactivity:~/Test$ rcss app/views/rcss/test.rcss
body {
  color: #000;
  background-color: #fff;
}
---< snap >---

What am I still missing? :-}

> Actually a simple plugin would just need a one line init.rb:
>
> require "rcss"
>
> :)

Sounds cool, not too hard :-) -- what about the controller and the route
though. The Markaby plugin (seems to be a good example) doesn't require
you to have any of both...
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-06 16:07
(Received via mailing list)
Hi,

On 06/03/06, Raphael Schmid <raphael@schwarzschmid.de> wrote:
> What am I still missing? :-}

Just followed the same steps and it works just fine. Could you send me
zipped test application together with a list of your gems ($ gem
list)?

> > Actually a simple plugin would just need a one line init.rb:

> Sounds cool, not too hard :-) -- what about the controller and the route
> though. The Markaby plugin (seems to be a good example) doesn't require
> you to have any of both...

You need SOME KIND of controller to serve .mab templates.

Route is just for convenience and clean urls. Controller is there so
that you can access your rcss file using /rcss/xxx.css notation. If
you rely on Rails defaults it should be possible to:

1. Add a line 'require "rcss"' to environment.rb
2. Generate a dummy controller (./script/generate controller rcss)
3. Put test file in app/views/rcss/test.rcss
4. Access it by http://localhost:3000/rcss/test (note, that there is
no .css at the end).

Now, as RcssController does contain some meaningful code and is
identical (or similar) on all deployments it would be nice to make it
part of distribution. And right now the only clean way of providing
controllers to existing applications is to create an Engine.
77961c972c437d6801714f45c3f2cc3c?d=identicon&s=25 Raphael Schmid (rapha)
on 2006-03-06 16:33
> Just followed the same steps and it works just fine. Could you send me
> zipped test application together with a list of your gems ($ gem
> list)?

Could you send me your email address? The forum doesn't show it, neither
does Rubyforge, and your blog seems to be down :-/.

Find the gem list below:

---< snip >---
rapha@proactivity:~$ gem list

*** LOCAL GEMS ***

ajax_scaffold_generator (2.1.0)
    Ajax scaffold generator is a rails generator for ajaxified scaffolds

daemons (0.4.2)
    A toolkit to create and control daemons in different ways

mongrel (0.3.6)
    A small fast HTTP library and server that runs Rails, Camping, and
    Nitro apps.

rake (0.7.0)
    Ruby based make-like utility.

rcss (0.3.1)
    Rcss - CSS Server-side Constants for Ruby/Rails

sources (0.0.1)
    This package provides download sources for remote gem installation

sqlite-ruby (2.2.3)
    SQLite/Ruby is a module to allow Ruby scripts to interface with a
    SQLite database.

sqlite3-ruby (1.1.0)
    SQLite3/Ruby is a module to allow Ruby scripts to interface with a
    SQLite3 database.
---< snap >---

> You need SOME KIND of controller to serve .mab templates.

I definitely did not have to create a controller for the Markaby plugin.
Looking at its init.rb, it seems to use some other facility... therein
you can see "ActionView::Base::register_template_handler :mab,
Markaby::View"

Once I get it working at all I'll try and play around with that.

Do you know of any statement of the core team of whether there was a
chance of RCSS getting into Rails itself anytime soon?

> Now, as RcssController does contain some meaningful code and is
> identical (or similar) on all deployments it would be nice to make it
> part of distribution. And right now the only clean way of providing
> controllers to existing applications is to create an Engine.

If not (reg. possib. of getting it into Rails), I imagine that would be
possible within scope of that plugin stuff Markaby also uses...

Best regards, Raphael
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-03-06 16:44
(Received via mailing list)
On 3/6/06, Łukasz Piestrzeniewicz <bragi.ragnarson@gmail.com> wrote:
> Now, as RcssController does contain some meaningful code and is
> identical (or similar) on all deployments it would be nice to make it
> part of distribution. And right now the only clean way of providing
> controllers to existing applications is to create an Engine.

I believe that with the new dependency loading mechanism coming in
Rails 1.1 you can provide a controller as part of a plugin without
using engines - all you need is to place the controller somewhere in
the load path. For instance, I just tried this out:

  /vendor/plugins/test_plugin/
     |- lib
          |- test_controller.rb

which contains:

  class TestController < ApplicationController
    def index; render :text => 'Get your ass to Mars!'; end
  end

This works from the url http://localhost:3000/test/index, so I don't
think that in this case RCSS *needs* to be an engine.

That said, you still can't load views, routes, migrations, static web
assets (images, stylesheets, javascripts) or plenty of other stuff
from plugins, nor can you easily override only a small part of a
controller included in this way (without using subclassing, but that
might make sense in some circumstances, to be fair).

On 3/5/06, Raphael Schmid <raphael@schwarzschmid.de> wrote:
> If possible, I'd like to try and not get any Engine whatsoever into my application.
> Just doesn't feel right. A plugin, like Markaby, would be great though :-)

I'm aware that some people think that engines 'smell bad' (and of
course everyone has a right to their opinion, however they have
derived it), but until Rails supports loading those types of files
from arbitrary locations, the Engines plugin will strive to fill that
gap for those people (me, certainly) who find it useful or even
necessary to isolate and/or share parts of their applications using
plugin-style entities. The emphasis there is on 'plugin'.

If you think that to any extent that type of behaviour might be useful
and should be provided by the Rails 'out of the box', send a message
to rails-core asking them to look into it. Nothing would make me
happier; reflecting the Rails philosophy, it would mean less code for
*me* to write ;-)

james
77961c972c437d6801714f45c3f2cc3c?d=identicon&s=25 Raphael Schmid (rapha)
on 2006-03-07 19:41
Hi again,

thanks to Łukasz' patience with me, I got it working now.
The secret is to use Ruby 1.8.4 -- my Ubuntu install had
1.8.3, d'oh.

One more question though: if I wanted to share a set of
variables between a couple of RCSS templates, where would
they be best put?

James:

I do think the RCSS behaviour should be available in RoR
out of the box. Personally, I don't need anything else
that Engines provides. You will probably have had your
fair share of discussion about it on rails-core and the
Core Devs will have their reasons for not including it...
for me it's just a gut feeling that I'd better not use it.
In no way did I want to rate it in any way, be it positively
or negatively.

However, since there's RJS I'm much hoping for RCSS to get
it. It definitely does make some things easier.

Best regards,
         Raphael
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-07 20:37
(Received via mailing list)
On 07/03/06, Raphael Schmid <raphael@schwarzschmid.de> wrote:
>
> One more question though: if I wanted to share a set of
> variables between a couple of RCSS templates, where would
> they be best put?


Unfortunately ERB support is somewhat broken in current gem. Neither
methods
nor variables from controller/helpers are available in rcss file.

Svn version drops ERB entirely but instead provides support for
server-side
includes. On the other hand it's an Engine... ;)

Regards,
77961c972c437d6801714f45c3f2cc3c?d=identicon&s=25 Raphael Schmid (rapha)
on 2006-03-07 23:21
> Unfortunately ERB support is somewhat broken in current gem. Neither
> methods nor variables from controller/helpers are available in rcss file.

> Svn version drops ERB entirely but instead provides support for
> server-side includes. On the other hand it's an Engine... ;)

That sounds great, for me at least it does.
I've entirely switched to Markaby, so having ERB in the RCSS files would
have introduced kind of an inconsistency... but if Markaby has the
helper
methods/variables available, they're surely not dependant on ERB?

What are your plans for the near / the distant future? What direction
would
you like to bring RCSS into?
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-03-08 00:03
Łukasz Piestrzeniewicz wrote:
> Unfortunately ERB support is somewhat broken in current gem. Neither  methods
> nor variables from controller/helpers are available in rcss file.
>
> Svn version drops ERB entirely but instead provides support for  server-side
> includes. On the other hand it's an Engine... ;)

Why drop ERB? That seemed like the whole point of doing RCSS. Personally
I was planning to use it only for ERB and don't care at all about SSI.

Mostly I want to use RCSS for customizing CSS based on values stored in
models. I was about to write it for myself when I happily found it
already existed, but it seems that you are taking it in a direction that
isn't as useful as I'd hoped. I may have to just grab the code and
modify it for my own purposes, but I'd be interested in hearing why ERB
isn't being supported anymore. Is there a technical problem, or is it a
philosophical issue about portability of CSS files?

thanks,
--josh
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-14 19:00
(Received via mailing list)
On 08/03/06, Josh Susser <josh@hasmanythrough.com> wrote:
> Why drop ERB? That seemed like the whole point of doing RCSS. Personally
> I was planning to use it only for ERB and don't care at all about SSI.
>
> Mostly I want to use RCSS for customizing CSS based on values stored in
> models. I was about to write it for myself when I happily found it
> already existed, but it seems that you are taking it in a direction that
> isn't as useful as I'd hoped. I may have to just grab the code and
> modify it for my own purposes, but I'd be interested in hearing why ERB
> isn't being supported anymore. Is there a technical problem, or is it a
> philosophical issue about portability of CSS files?

I simply lack the time necessary to implement ERB evalutaion in proper
(read: working) way.
77961c972c437d6801714f45c3f2cc3c?d=identicon&s=25 Raphael Schmid (rapha)
on 2006-03-14 20:20
> I simply lack the time necessary to implement ERB evalutaion in proper
> (read: working) way.

I don't mean to be ungrateful, but how hard would it be to make @import
(or another form of inclusion) work for RCSS files? Right now, the
variables defined with `@server constants' are not available in files
that @import other files containing @server constants.

The ability to define variables was what drew me personally to RCSS, but
not being able to share them between files is definitely a problem...
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-03-14 20:42
Łukasz Piestrzeniewicz wrote:
> I simply lack the time necessary to implement ERB evalutaion in proper
> (read: working) way.

Maybe I can help out with the project. I'm going to need that
functionality anyway, so I might as well. I'm not interested in the
server-side includes, but defintely want an RCSS plugin that uses ERB.
Email me directly if you want some help on that (your email address
doesn't show up on the forum list reader).

--josh
http://blog.hasmanythrough.com
This topic is locked and can not be replied to.