Examples

Ruby vs PHP Syntax Examples

I was mulling through some old code I had done on a drupal PHP based project a year ago and thought it might be interesting to show a few examples of syntax differences of basic PHP and Ruby one liners.

I only did around 15 of them but feel free to add your own in the comments if you have any that show off clear syntax differences between Ruby and PHP. You be the judge of course.

Examples of Ruby Syntax vs PHP

ActionMailer Examples: Responses, Welcome Greetings, Sendmail, Templating and Performance

Using Rails ActionMailer The Right Way

By providing the full name in the @from field, you avoid having emails say they were sent from congratulations:

def new_registration(user)
@subject = ‘Welcome!’
@recipients = user.email
@from = ‘Ruby on Rails Blog <congratutions@domain.com>’
@body[”user”] = user
end

Now the email will show that it’s from Ruby an Rails Blog. This passed some simple tests with yahoo and gmail with no messages being sent to the spam folder. Everything comes through perfectly.