SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ruby Questions...

    I am about to start learning ruby...

    everything I've read so far, was about running ruby on the console, I want to save it and upload it to my server, so I can allow anyone to run the script, then I could write a website or application of some sort with it.

    So, what file extension does it need to be saved as, and what are the proper ways to start a ruby file?

    Can ruby be used to write a website? meaning could I have valid XHTML strict and all that stuff, with proper HTML codes, yet still harness ruby's functionality?

    Thanks,

    Edit:

    here, I can sum it up:
    Can I use Ruby in basically the same way I use PHP?
    ~Jabird
    Jabird.com
    If I were binary... I'd be all 1's for you.
    BBCode trouble?

  2. #2
    SitePoint Evangelist CapitalWebHost's Avatar
    Join Date
    Apr 2003
    Location
    Albany, NY
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your host would need to set up Ruby on Rails support before it would work. This involves them installing Ruby, RubyGems, Rails, and mod_fastcgi, and doing a recompile of Apache. It's not for the faint of heart.

    Then you would need shell access to run Rails to create apps, or do it on your local PC and then upload them and modify the shebang in the app config files.

    Site5 has Ruby support now.

  3. #3
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome, I'm basically the host (really my dad), but I'm the server guy, and I have my own dedicated box, so no problem... just gotta install RubyGems, Rails, an mod_fastcgi, and recompile Apache.... yay....

    Does that mean after I do all that, I can design in essentially the same way I do PHP? Do all my HTML stuff, enter ruby, do the ruby stuff, exit ruby, do the ending HTML stuff, save, upload?

    Also, if thats the case, how do I enter ruby? is it as simple as something like <?ruby ?

    Thanks,

  4. #4
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if I was going to start learning ruby this is where I would start:

    http://www.ruby-lang.org/en/

    you can do pretty much anything with ruby, but it is not an embedded script like PHP, although there is a thing called pRuby that lets you embed ruby into php documents.

    I don't know ruby so thats about all I can help you with.

  5. #5
    SitePoint Zealot bronze trophy
    Join Date
    Jun 2004
    Location
    Stockholm, Sweden
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, Ruby on Rails is a full-blown webapplication framework. If you just want to embed ruby into HTML you can check out:

    eruby and mod_ruby.
    If there is a way to overcome the suffering, there is no need to worry; if there is no way to overcome the suffering, there is no point to worry.
    - Shantideva

  6. #6
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by KTottE
    Well, Ruby on Rails is a full-blown webapplication framework. If you just want to embed ruby into HTML you can check out:

    eruby and mod_ruby.
    This is what you need to get Ruby running in basically the same manner the average person uses PHP in now.

    If you want something nicer though, definitely try Rails

  7. #7
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I already have eruby and mod_ruby...

    so how can I begin using it?

    No one has answered my question of how to enter ruby, and the file type I need to save it as...
    ~Jabird
    Jabird.com
    If I were binary... I'd be all 1's for you.
    BBCode trouble?

  8. #8
    SitePoint Zealot bronze trophy
    Join Date
    Jun 2004
    Location
    Stockholm, Sweden
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you even check the links I provided? On the mod_ruby page there is a link to their documentation, which describes quite clearly how to install mod_ruby for apache.

    http://wiki.modruby.net/en/
    If there is a way to overcome the suffering, there is no need to worry; if there is no way to overcome the suffering, there is no point to worry.
    - Shantideva

  9. #9
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by jabird
    I already have eruby and mod_ruby...

    so how can I begin using it?

    No one has answered my question of how to enter ruby, and the file type I need to save it as...
    If you mean embedding Ruby into a script with HTML code it goes something like this:
    Code:
    <div id="whatever">
    <%
    #ruby code in these blocks
    %>
    </div>
    It's similar to how ASP and JSP do it.

    As for file type, I think it's saved with a .rhtml extension, and regular Ruby scripts are saved as .rb files.

  10. #10
    SitePoint Zealot bronze trophy
    Join Date
    Jun 2004
    Location
    Stockholm, Sweden
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't actually matter, you can tell apache to interpret it as whatever you want. You can call them .mynotsobadbutlanguagefilteredwordextension if you want.

    edit language filter....
    If there is a way to overcome the suffering, there is no need to worry; if there is no way to overcome the suffering, there is no point to worry.
    - Shantideva

  11. #11
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Yakima WA.
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use .rb and .rhtml

    The standard way to use eruby or erb and mod_ruby to develop like you would with php is to get eruby and mod_ruby set up on your apache server and set the extension for ruby cgi scripts to .rb and php like scripts to .rhtml. Then you would write and .rhtml file like so:

    <html>
    <body>
    <%= foo %>
    <p> whatever</p>
    <% if bar %>
    text goes here
    <% else %>
    some other text
    <% end %>

    be carefull inside eruby templates as you _cannot_ use puts and print like you would think you can. that is what the <%= tag is for, for output. If you do not like that then you can do this but its not that nice:

    <% _erbout << "some text" %>
    and that will append to the output buffer. You can also set up eruby so that you can write lines of ruby code like this:

    % everything on this line will be interpreted as ruby code
    <p> this line is just html</p>
    % more ruby code

    Also if you are writing say a ruby method that does not output test but just defines some logic or functionality you can do this and it will not output blank lines:

    <% def somemethod arg; return "foobar"; end -%>

    Note the -%> that keeps that section from outputting extra whitespace in your doc.

    For .rb files you need the
    #!/usr/local/bin/ruby
    line for your .rb script to work. Then you use it mor elike a perl cgi script with just normal ruby code and anything that you puts or print will go to the browser.
    Hope that helps. Let me know if you have more questions or need help getting stuff set up. Also check out my other thread with instructions on how to install the whole ruby/rails/lighttpd/fcgi/php stack on OSX, linux and BSD

  12. #12
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KevinR
    if I was going to start learning ruby this is where I would start:
    http://www.ruby-lang.org/en/
    Uhm. That homepage has two security/vulnerability alerts already!

    # XMLRPC.iPIMethods Vulnerability
    [2005-07-01] by shugo
    On Fri Jun 17 2005, a vulnerability of XMLRPC.iPIMethods was reported in [ruby-core:05237]. Remote attackers can execute arbitrary commands by this vulnerability.
    # Ruby vulnerability in the safe level settings
    [2005-10-02 10:58] by matz
    The Ruby versions listed below have a vulnerability that allows an arbitrary code to run bypassing the safe level check.

    Date published: 2005-10-02
    Not a good start is it?

    - Vince

  13. #13
    SitePoint Zealot bronze trophy
    Join Date
    Jun 2004
    Location
    Stockholm, Sweden
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have any idea how many security vulnerabilities there are in, lets say, PHP?

    I am not saying Ruby is more (or less) safe than PHP, I'm saying it's not shock and amazement that software has security holes.

    The fact that they're listed means that somebody is working on fixing them.

    edit

    Going a step further, I trust developers/software who publically announces vulnerabilities more than I trust developers/software who hides the vulnerabilities.
    If there is a way to overcome the suffering, there is no need to worry; if there is no way to overcome the suffering, there is no point to worry.
    - Shantideva

  14. #14
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    XMLRPC has always had problems on all platforms. PHP especially had plenty.

    # Ruby vulnerability in the safe level settings

    Ruby provides the ability to execute foreign code. So you can place Ruby code in a textarea and execute it on the server. And for this it has a safe level setting which prevents that code from doing harm. Of course it contains vulnerabilities, and it will always will, and your site will forever be at risk if you're stupid enough to use that feature. And that's not just a Ruby problem. Does PHP provide such facility ?

  15. #15
    SitePoint Zealot bronze trophy
    Join Date
    Jun 2004
    Location
    Stockholm, Sweden
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes and no, you can eval() PHP code from a textarea if you want, something like:

    PHP Code:
    <textarea id="MyCode"></textarea>

    <?php

    if ( isset($_REQUEST['MyCode']) )
    {
        eval(
    $_REQUEST['MyCode']);
    }

    ?>
    It doesn't provide an equivalent of the Ruby Safe level.
    If there is a way to overcome the suffering, there is no need to worry; if there is no way to overcome the suffering, there is no point to worry.
    - Shantideva


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
  •