Ruby on Rails is very nice - I never got into php because it looked so damned ugly, but I do have some experience of RoR.
FYI it is:
Object oriented
Uses model, view, controller architecture
Uses "convention of configuration".
has a nice object reference model.
So here's an example:
You want an object called a 'user'.
You use a generator, and it builds a 'user' model, controller and table, and a user folder in the views.
Then you can do things in the model like this:
validates_presence_of :name,
:login
validates_uniqueness_of :name,
:login
has_one :account
has_many :projects
RoR then creates a bunch of rules that ensure the above happens, and adds a relationship to an 'account' model.
In the controller you define actions, so you might have something like this:
def Home
@user_projects = Projects.find(:all, {:conditions => "user_id = ?" current_user.id})
end
Then in the view (which is where the HTML is constructed) you might have:
home.rhtml
<h1>Welcome <%=current_user.name%></h1>
<h2>These are your projects</h2>
<%@user_projects.each do |up|%>
<%=link_to "#{up.name}", :action => 'show', :id => up.id %><br/>
<%end>
This would then show a link to each of the projects that the user owns, taking them to the page defined in the project views as show.rhtml
Hope this explains it a bit, I don't really know how it compares to php as I said I never got into it.
|