SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Questions about using RoR

    I've been using PHP with all of my sites the past 3 years and am about 1/4 of the way through Agile Web Development with Rails. I have a couple of questions and would appreciate it if someone could answer them.

    Should I just use RoR on websites that require database connections on just about every page? I'm confused about when to use PHP or RoR or would it be best to just use RoR all the time?

    How about in this example? Say I have a site that has 15 pages, only one of which that displays info from a database for a calendar. Would it be better to use PHP or RoR in this situation?

    In PHP I use includes a lot for templates for my header, footer, sidebar, etc. Can someone give me an example of how to do this in RoR? Is this what most sites running RoR do or do they just have the header/footer on multiple pages? I like using includes because then I can just update one page when I need to make a global change.

    If someone who knows HTML were to ask what RoR is, what would be a good way to explain it in laymans terms (instead of just saying it's a web-based framework that uses the ruby scripting language)?
    John Saunders

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JohnSaunders
    Should I just use RoR on websites that require database connections on just about every page? I'm confused about when to use PHP or RoR or would it be best to just use RoR all the time?
    Use it when the features would make creating the website easier than PHP. If you need a DB connection, it's almost a no-brainer. However, sometimes, when working with forms and validation and displaying things, it may easier to use Rails. Rails is not a web application panacea. I sometimes use PHP to do certain things also, including one-pagers. But I don't believe I've ever not used rails for anything larger.

    Quote Originally Posted by JohnSaunders
    How about in this example? Say I have a site that has 15 pages, only one of which that displays info from a database for a calendar. Would it be better to use PHP or RoR in this situation?
    Would it be easier to use PHP or RoR? If you already have it running with PHP, I would just keep it that way. Also, if you want AJAX functionality in it, it may be easier to use rails. You could put the other 14 pages, in PHP, in the public folder.

    Quote Originally Posted by JohnSaunders
    In PHP I use includes a lot for templates for my header, footer, sidebar, etc. Can someone give me an example of how to do this in RoR? Is this what most sites running RoR do or do they just have the header/footer on multiple pages? I like using includes because then I can just update one page when I need to make a global change.
    Use a layout. A layout is an RHTML file which SURROUNDS the template. You can include a sidebar partial in the header. The layouts go in app/views/layouts and you create them like a normal HTML page with ERB markup. Then, wherever you want the Rails HTML to go you put this:
    Code:
    <%= yield %>
    That's it! The layout which is used is set from the controller.

    Quote Originally Posted by JohnSaunders
    If someone who knows HTML were to ask what RoR is, what would be a good way to explain it in laymans terms (instead of just saying it's a web-based framework that uses the ruby scripting language)?
    Its a framework to building web applications more effortlessly. (?)
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer

  3. #3
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So a typical layout looks like:

    Code:
    <html>
    <head>
    <%= stylesheet_link_tag 'style' %> <!-- You can use inline Ruby here. This creates a <link ... /> tag -->
    </head>
    <body>
    <h1>My Site</h1>
    <%= yield %> <!-- yield will be replaced by a page specific template -->
    </body>
    </html>
    I recommend PHP for a really simple thing (like email-form, shoutbox, etc), because it is easier to set up. The amount time you save by coding it in Rails will be nullified by the amount of time you spend extra setting things up. Rails is better for medium/large things. A good thing to ask yourself is: "is this site an application?" if it is, chances are good Rails is the way to go.

  4. #4
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the answers.

    So for a site that would have several pages of content that would be fetched from a database would it be best to set up the backend/CMS using RoR then just use PHP to fetch the info from the databases that would display the info (such as a list of members, calendar, etc.)?
    John Saunders

  5. #5
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I would do everything in RoR, that's easier. If already use RoR for the backend, it will be easier to use it for the frontend too. (otherwise you'll be re-doing things in PHP, like database handling (model)). You can put static HTML pages in the public folder.

  6. #6
    SitePoint Evangelist
    Join Date
    Apr 2005
    Posts
    485
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JohnSaunders
    Thanks for the answers.

    So for a site that would have several pages of content that would be fetched from a database would it be best to set up the backend/CMS using RoR then just use PHP to fetch the info from the databases that would display the info (such as a list of members, calendar, etc.)?
    John, for small apps, i think you go with what you know. if you know php and are learning rails, developing in php will be faster.

    if you want to learn RoR and don't mind spending more time, RoR is the no brainer.

    if you know you will want to run RoR apss on the same server down the road, you reduce complexity by coding the simple app in RoR so you don't have to admin for PHP and Ruby.

    ruby is comparable to php inthat they are both scripting languages. however, the syntax is different and the structure is different.

    Rails is a system to organize your ruby code AND some ruby code to perform certain functions. for example, adodb is my php db abstration layer. activerecord performs this function (and more!) in rails. rails also has code that will extract information from your db and display it if you follow certain conventions. this is done automagically. that's what rails can do for you.

    RoR is nothing magical, rather, it is a well thought out language applied in a well thought out way. its focus was on OO programming, not procedural programming.

    i'm just learning it, too. just when i'm comfortable with php... i need to learn something new. having said that, applying the principles in the agile web dev with rails book, you will can easily improve your php coding style. i know i did.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •