Rails versus PHP in complex HTML/CSS

I have done a bunch of Rails stuff on my own and my company uses PHP.
I often have to integrate very complex HTML/CSS into PHP. I know that
the PHP looks more closer to the HTML than Rails because Rails has
alot of link_to and other macro like calls that generate alot of stuff
that you don't see in the template. I am wondering if that could make
it any tricker to generate the complex sort of HTML that we have done
with PHP ? I have been trying to promote Rails at my company, but
sometimes I try to imagine what sort of hurdles there could be in
trying to get people to like Rails. I remember some of the select()
calls I found hard to figure out at first in the templates because
they wheren't really well documented in the books that I have.

You can just write all the html you want in html.erb-files. Before the
server sends the html.erb-files to the client he dynamically replaces
the ruby code between <%-tags-%> so its just like the same using the
php <? ?> tags (well i at least think thats what they look like).

The helpers just generate html code for you u can just as easily write
by hand. They just try to simplify your code. If they dont provide the
functionallity you need you can easily wirte your own helpers that
generate the html code u need.

the PHP looks more closer to the HTML than Rails because Rails has
alot of link_to and other macro like calls that generate alot of stuff
that you don't see in the template. I am wondering if that could make
it any tricker to generate the complex sort of HTML that we have done
with PHP ?

you don't have to use it. you can still write 'pure' html or any
intermediate level of using html / ruby / rails

the partials are a great way to handle complex pages by splitting them
in small parts, especially for ajax that's a great thing (but maybe PHP
offers something like that, to, i'm not a PHP programmer)

Sure it does, in frameworks like symfony (symfony-project.com) you have
layouts, partials, slots and components as good as RoR.

I wouldn’t say “as good as”. “similar to a very old Rails version” would be more appropriate :slight_smile:

Best regards

Peter De Berdt

Wouldn't it be better to substantiate that with concrete examples?

And define "very old" while you're at it?

Symphony is one of the PHP frameworks that’s clearly inspired by Rails. The featureset is about the same as Rails < 1.2. I consider that a very old Rails version.

The best way to find out for yourself is develop in Rails most of the time and then being forced for one project to go back to PHP using Symphony. I’m not going to venture into discussions that eventually lead up to nothing, but doing a project in Symphony again felt limited and very unnatural, both PHP as a language and Symphony as a framework were to blame here. That doesn’t mean it doesn’t have its merrits, you can easily deploy its applications on shared hosts for example.

You posted this message on the Rails mailing list, what did you expect to hear? A lot of people here actually have a PHP background or still do some PHP.

Best regards

Peter De Berdt

Symphony is one of the PHP frameworks that's clearly inspired by
Rails. The featureset is about the same as Rails < 1.2. I consider
that a very old Rails version.

Didn't RoR jump from 1.2.6 directly to 2.0 ?

You posted this message on the Rails mailing list, what did you
expect to hear? A lot of people here actually have a PHP background
or still do some PHP.

I like RoR a lot but I use PHP and hence, symfony, in my day job (and Im
coming from a C / Perl background :slight_smile: I was just trying to get specific
details to compare the two. Like features of templating that are missing
in symfony (and/or vice versa). I realize this is a RoR list so I guess it
was stupid of me to look for a healthy discussion of any kind.

You can write any HTML you want in ERB templates. You don't have to
use the helpers (which are sometimes rather limited) if they are not
appropriate for you. But in the example with links, at the very least
you should use url_for to generate the URL from your routes instead of
putting it in manually... that would be very difficult to maintain.
But it's not any more difficult to generate complex and css, because
rails' templates are just embedded ruby, similar to how PHP works.

Symphony is one of the PHP frameworks that’s clearly inspired by

Rails. The featureset is about the same as Rails < 1.2. I consider

that a very old Rails version.

Didn’t RoR jump from 1.2.6 directly to 2.0 ?

Sure, that’s why I said < 1.2. From my experience, Rails 1.2 and 2.0 introduced a fair number of interesting and useful conventions/concepts, such as REST. Symphony is (still) lacking those and it slows me down.

You posted this message on the Rails mailing list, what did you

expect to hear? A lot of people here actually have a PHP background

or still do some PHP.

I like RoR a lot but I use PHP and hence, symfony, in my day job (and Im

coming from a C / Perl background :slight_smile: I was just trying to get specific

details to compare the two. Like features of templating that are missing

in symfony (and/or vice versa). I realize this is a RoR list so I guess it

was stupid of me to look for a healthy discussion of any kind.

What I like about Ruby, is how it has enabled Rails to use Ruby itself as a templating language (using ERB) instead of having to fall back on a proprietary templating language such as Smarty or the likes. The Rails helpers such as link_to etc do make the view more easy to read then awkward constructions like . That’s the reason I don’t mind using them at all.

Best regards

Peter De Berdt

I like RoR a lot but I use PHP and hence, symfony, in my day job (and Im

coming from a C / Perl background :slight_smile: I was just trying to get specific

details to compare the two. Like features of templating that are missing

in symfony (and/or vice versa). I realize this is a RoR list so I guess it

was stupid of me to look for a healthy discussion of any kind.

What I like about Ruby, is how it has enabled Rails to use Ruby itself as a templating language (using ERB) instead of having to fall back on a proprietary templating language such as Smarty or the likes. The Rails helpers such as link_to etc do make the view more easy to read then awkward constructions like . That’s the reason I don’t mind using them at all.

And by falling back to a templating language in php, I mean it’s just more interesting to do so for the sake of maintainability. You can of course just use php code in the page, but in the end it would be very ugly and hard to maintain.

Best regards

Peter De Berdt

You may be interested in our full page design environment for Rails -
the Visual Rails Workbench - which will be launched in a forthcoming
update to Ruby In Steel and which I'll demo on our blog next week.

best wishes
Huw Collingbourne

SapphireSteel Software
Ruby and Rails In Visual Studio
http://www.sapphiresteel.com

What I like about Ruby, is how it has enabled Rails to use Ruby
itself as a templating language (using ERB) instead of having to fall
back on a proprietary templating language such as Smarty or the
likes.

I agree, ERB is definitely much more readable and maintainable than
PHP embedded into HTML, but unfortunately there is still the issue of
it evaling the code. Template engines like Smarty serve another very
important purpose - providing a secure way for designers and end users
to edit templates without eval'ing the code and exposing the context
of the application in which they run.

If I'm not mistaken, what you're looking for are helpers. Helpers
allow you to do complex things and import them into your design.
Infact, all the "link_to and other macro like calls" are actually
rebuilt helpers that come with Rails... but you can also make your own
to do other things.

SIMPLE EXAMPLE
If you are using CSS heavily, you're surely using unordered lists for
navigation somewhere in the design. You could create a NavMenu helper
that would build an ordered list with links simply by having this in
your layout/view: <%= navmenu @subcategories %>

You could also use Partials as mentioned above.

Does that help?

~ mel

symfony doesn't use any additional layers (like Smarty) for templating,
just PHP (which are usually just echoing variables kind of like ERB in
Rails). (You can install plugins to use other kinds of markup if you want
to though).

symfony also has helpers for generating URLs, links, javascript, etc:
http://www.symfony-project.org/book/1_0/09-Links-and-the-Routing-System#Hyperlinks,%20Buttons,%20and%20Forms

Uses routing too:
http://www.symfony-project.org/book/1_0/09-Links-and-the-Routing-System#Rules%20and%20Patterns

True, we dont have things like RJS and I dont think RESTful practices are
there yet. And the ORM layer, Propel, doesn't have migrations (you can use
Doctrine which *does* have migrations).

Like Ruby, symfony also uses OOP throughout (based on PHP5).

Having written a PHP framework and then moved exclusively to Rails, I would venture the following comments:

- The most expensive task for most pages was instantiating the framework. Rails does this at startup. Love it or hate it, this is an efficiency.
- The Rails ecosystem is vital and my experience with PHP was that it was fragmented once you got outside the core libraries.
- Ruby, the language, is less like C and more like Smalltalk or Python. It expresses newer thinking in terms of dynamic language design. I wrote a test runner in PHP5 about 8 months ago, and it was very difficult. The PHP introspection isn't what Ruby's is, nor is it possible (IMO) to write a natural feeling DSL such as Rails.
- The testing tools for PHP have never felt right to me. I know people are using PHPUnit to good end, but I never felt it really fit the bill.

At the end of the day, it's what you feel comfortable with. The buzz around Rails has had time to settle and one would expect that if there were no substance there would be a die-off. I don't see that happening, so my interpretation is that Rails has material value to developers. How many are gainfully employed writing Rails applications is subject to debate, but there is no doubt that the Rails technology has been embraced in a number of credible shops. Amazon, Sun, Microsoft, and Apple are (to name a few) all taking Rails seriously.

if(this->looks() == good->toYou) {
   tryRails();
}
else {
   stayWithPHP();
}

- The most expensive task for most pages was instantiating the
framework. Rails does this at startup. Love it or hate it, this is an
efficiency.

Just to clarify: am I correct in saying this is true when using fastcgi or
handing off to something like Mongrel right?

- The Rails ecosystem is vital and my experience with PHP was that it
was fragmented once you got outside the core libraries.

Yes and no. There's several frameworks for PHP and some of them have
really good community around them (symfony is a good example).

- Ruby, the language, is less like C and more like Smalltalk or
Python. It expresses newer thinking in terms of dynamic language
design. I wrote a test runner in PHP5 about 8 months ago, and it was
very difficult. The PHP introspection isn't what Ruby's is

True, but then OOP is PHP is pretty new compared to Ruby.

At the end of the day, it's what you feel comfortable with. The buzz
around Rails has had time to settle and one would expect that if there
were no substance there would be a die-off.

Do you know of any BIG sites that are built from Rails? I can't think of
any off the top of my head though Im sure someone will chime in with one
that Ive forgotten about!

I don't see that
happening, so my interpretation is that Rails has material value to
developers. How many are gainfully employed writing Rails applications
is subject to debate, but there is no doubt that the Rails technology
has been embraced in a number of credible shops. Amazon, Sun,
Microsoft, and Apple are (to name a few) all taking Rails seriously.

The good news is that a lot of Rails' ideas have flowed out into other
languages/frameworks. A Good Thing.

if(this->looks() == good->toYou) {
   tryRails();
}
else {
   stayWithPHP();
}

I dont see this as an either/or kind of thing. If I could use Rails in my
day-job, I would. (I play with it for personal stuff only right now).

Do you know of any BIG sites that are built from Rails? I can’t think of

any off the top of my head though Im sure someone will chime in with one
that Ive forgotten about!

http://yellowpages.com

Twitter

BBC Video and Audio Archive

Best regards

Peter De Berdt