Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails or a PHP framework

I am a capable programmer and I write software for a living. I am taking up a new project to build a website that has a bunch of forms that perform CRUD operations on a database and some multimedia. I am very familiar with PHP and Python and have written some websites in them. I have written some rake tasks and a few ruby scripts that run in production, but I never wrote any websites in ruby. I am considering using Rails, but I have the following questions. It would be great to know the answers to any/all of these:

  • The project should be done in a month and is very time sensitive. Is 1 month enough for learning with and building a website in RoR?
  • Writing direct SQL queries is one of my strengths and I would like to use it. I heard that RoR is a pain to use if I am writing SQL queries directly. Is this true? Or can I just say execute a query, give me the results (as a list or dictionary) and then I will tell you how to render them?
  • I have heard that RoR does joins in memory and doesn't use the facilities offered by the database. Is this correct?
  • I need to create a website that displays a lot of Images, videos and Java applets. Would RoR hinder my ability to do this?
  • I am OK using a PHP framework. Is this a bad idea? If not, which PHP framework is closest to Rails in terms of programming convenience.
like image 438
mansu Avatar asked May 12 '09 21:05

mansu


3 Answers

Answering your questions in order:

  1. You could certainly learn Rails in that time. It's enough time to build a Web site too, but whether it's enough time for you to build your Web site is a different question. I would personally not want to try such a thing on a tight deadline.
  2. You can write your own SQL queries, but there's little point to using Rails if you are going to work around all of its features.
  3. Joins are normally done as part of the database queries generated by ActiveRecord.
  4. Using ROR is pretty much orthogonal to having images, videos, etc. on a page.
  5. I haven't used it, but CakePHP aims to be quite Railsy. Zend and CodeIgniter are more popular and I'm told better by people who have used all three, though.
like image 186
Chuck Avatar answered Oct 18 '22 19:10

Chuck


The project should be done in a month and is very time sensitive. Is 1 month enough for learning with and building a website in RoR?

Given the experience you describe I imagine one month to learn and build a simple-ish app (especially if it is CRUD based) should be enough. If there is a significant level of complexity I would be loath to learn a new technology and deliver a complicated site in one month.

Writing direct SQL queries is one of my strengths and I would like to use it. I heard that RoR is a pain to use if I am writing SQL queries directly. Is this true? Or can I just say execute a query, give me the results (as a list or dictionary) and then I will tell you how to render them?

The rails way is to use the ActiveRecord object mapppings it gives you (and mostly these work very well) It is also very easy to write direct SQL if that is what you want to do

ModelName.find_by_sql('your query')

is how you do that

I have heard that RoR does joins in memory and doesn't use the facilities offered by the database. Is this correct?

ActiveRecord does a lot for you, but wherever performance is an issue, as above you can write your own SQL to leverage the advantages of the database.

I need to create a website that displays a lot of Images, videos and Java applets. Would RoR hinder my ability to do this?

I don't see why it should. There are lots of gems and plugins out there which help with this sort of functionality, so it may well be the case that a lot of code could already be written for you.

I am OK using a PHP framework. Is this a bad idea? If not, which PHP framework is closest to Rails in terms of programming convenience.

I'll let a PHP expert answer this bit.

like image 30
DanSingerman Avatar answered Oct 18 '22 19:10

DanSingerman


  • The project should be done in a month and is very time sensitive. Is 1 month enough for learning with and building a website in RoR?

If it's time-sensitive, stick with what you know.. That said, Rails has lots of plugins to handle things like image-uploads which may save you a lot of time. Rails has "scaffold generators" which create basic CRUD applications in a single command:

./script/generate scaffold title:text description:text when:datetime

..will generate the controllers/views to create/edit/delete items. You can then easily wrap nicer looking HTML around it, add authentication (via restful_authentication), and you may have your completed application in a few hours..

  • Writing direct SQL queries is one of my strengths and I would like to use it. I heard that RoR is a pain to use if I am writing SQL queries directly. Is this true? Or can I just say execute a query, give me the results (as a list or dictionary) and then I will tell you how to render them?

There's very few situation where you'd need to write SQL with ActiveRecord, but you can. RoR is still Ruby code, so you can always use a MySQL library and do away with ActiveRecord if you really need to write raw SQL (but, again, you almost certainly don't)

  • I have heard that RoR does joins in memory and doesn't use the facilities offered by the database. Is this correct?

There's no reason ActiveRecord cannot perform JOIN's via SQL queries, the ActiveRecord::Associations::ClassMethods mentions associations being performed via JOIN's.

Besides, even if it does do JOINs through memory, it's worked perfectly well for however long Rails has been around..

  • I need to create a website that displays a lot of Images, videos and Java applets. Would RoR hinder my ability to do this?

No. They're all just bits of HTML, which Rails can output as easily as any other framework.

  • I am OK using a PHP framework. Is this a bad idea? If not, which PHP framework is closest to Rails in terms of programming convenience.

Absolutely. If you don't go with Rails, use a PHP framework!

I would recommend against choosing a framework based on "how close to Rails" it is. PHP isn't Ruby. Trying to "port" (in a manner) a framework to a different language rarely works as well as writing a framework for that language.

As I commented on Chuck's answer, "CodeIgniter and Zend are good PHP web-frameworks. CakePHP is a good Ruby on Rails imitation"..

I found CodeIgniter felt much more like PHP (in a good way), it's documentation is also my favourite of any project I've used!

The Zend Framework is very modular, you can drop bits of Zend into an existing PHP app, or use it's MVC routing system.

CakePHP seems to be trying to make PHP act like Ruby, rather than making a framework that fits nicely with PHP.


All that said, the reason you use Ruby on Rails is the community (and thus all the plugins and stuff that revolve around it).

For example, paperclip plugin makes it extremely easy to an image-upload form (along with thumbnailing). To use it you add (to your model):

has_attached_file :photo, :styles => {:thumb=> "100x100#", :small  => "150x150>" }

Then in your view, where you want the upload form to be, add:

<% form_for :user, :html => { :multipart => true } do |f| %>
  <%= f.file_field :photo%>
<% end %>

That's it.


What I would recommend is spend a day making something simple in Rails. There's countless great tutorials (Railscasts are a good, random, example) and plenty of books on it. See if you like it, if not try CodeIgniter, Zend or CakePHP (or Django, or Merb, or.... Just don't spend the whole month trying frameworks!)

like image 42
dbr Avatar answered Oct 18 '22 19:10

dbr