#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    9
    Rep Power
    0

    Embedded Ruby without Rails


    Hi. I started learning ruby and ruby on rails last week. I have a lot of experience with C and perl, including database manipulation with via cgi and using perl to generate javascript, etc.

    Ruby seems very nice, but I am starting to find the rails class=table concept repulsive. Also, I do not need rails to do what I want *if* embedded ruby remains feasible. It is not clear to me how realistic that is: can I set out that way and expect to get server support? How? Or is the erb limited to a rails framework, and I should just go learn php instead?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2009
    Posts
    4
    Rep Power
    0
    Originally Posted by mk27
    Hi. I started learning ruby and ruby on rails last week. I have a lot of experience with C and perl, including database manipulation with via cgi and using perl to generate javascript, etc.

    Ruby seems very nice, but I am starting to find the rails class=table concept repulsive. Also, I do not need rails to do what I want *if* embedded ruby remains feasible. It is not clear to me how realistic that is: can I set out that way and expect to get server support? How? Or is the erb limited to a rails framework, and I should just go learn php instead?
    You should probably learn PHP to be honest, but Ruby is a fine language :P
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    ERB is part of Ruby proper. You can use it without any attachment to Rails. For example:
    Code:
    irb(main):001:0> require 'erb'
    => true
    irb(main):002:0> erb_str = "<%= x %>"
    => "<%= x %>"
    irb(main):003:0> template = ERB.new erb_str
    => #<ERB:0x35b394 @safe_level=nil, @src="_erbout = ''; _erbout.concat(( x ).to_s); _erbout", @filename=nil>
    irb(main):004:0> x = 42
    => 42
    irb(main):005:0> puts template.result binding
    42
    => nil
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog

IMN logo majestic logo threadwatch logo seochat tools logo