Skip to content
Jul 30 10

Sending E-mail with Rails via Gmail (Spoiler Alert! this is for dummies)

by dkberktas

Yes, Rails is super cool, everything is super easy, and so far I really fall in love with it. But why is it that hard to send an e-mail via Gmail !?!

So after messing up a couple of git branches, I finally get it work, yey!

Here are the steps:

  • Watch the railscast about sending email
  • Install the gem with TLS
  • sudo gem install ambethia-smtp-tls -v '1.1.2' --source http://gems.github.com
  • Add the following to your environment.rb (Be careful after the Rails::Initializer.run do |config| block. )
  • #to the top of file
    require 'smtp-tls'
    
    ...
    #to the very end of the file
    ActionMailer::Base.smtp_settings =
    {
        :address => "smtp.gmail.com",
        :port => 587,
        :domain => "gmail.com",
        :user_name => "dkberktas",#not with @gmail.com
        :password => "xxxyyyzzz",
        :authentication => :plain,
        :enable_starttls_auto => true
    }
  • Run the mailer generator by
  • script/generate mailer user_mailer
    
  • Go to UserMailer class and add the method
  •   def registration_confirmation()
        recipients  "xxx@gmail.com"
        from        "xxx@gmail.com"
        subject     "Thank you for being that awesome"
        body        "no I am just kidding" #if you want to pass parameter do it like this -- > ":user => user"
      end
    
  • Add a sample method to application controller and add it to the routes.rb
  • #in application controller
      def mailDeneme
        UserMailer.deliver_registration_confirmation()
        render :text => "OK"
      end
    #in routes.rb
    map.mail  '/mail',  :controller => 'application', :action => 'mailDeneme'
    

If you see an error like this:

Net::SMTPAuthenticationError (530 5.7.0 Must issue a STARTTLS command first.

You miss the item above about  installing smtp-tls gem. Read it again again, or check this forum post.

ps. This is the official rails guide.
ps2. this is another link.

Jul 22 10

Background Jobs in Rails — Delayed_job

by dkberktas

Rails has lots of options for background jobs, the list below is a collection of link that help my choose Delayed Jobs which is a simple and capable enough one.

  • Blog post which is a good summary of alternatives — (kind of a survey)
  • A related question on StackOverflow
  • Blog post about Delayed Job link
  • Heroku suggests Delayed Job, so this is the one I am looking for ;)
  • and finally this is the Heroku guide for using Delayed Job
  • Railcast about Delyaed_job
  • Tip&Tricks

If you are interested, we are using Delayed Job for creating our heatmaps for remotespots usability testing site. Heatmap project will probably work as a separate project so that others can also use it for creating heatmaps on top of their images. Stay tuned for the heatmap side project!

Steps for Delayed_job

  • Install the plugin from github (from collectiveideas) with
  • script/plugin install git://github.com/collectiveidea/delayed_job.git
  • Create the model
  • script/generate delayed_job
    rake db:migrate
  • You can set priority and a certain time for the job to be put on queue.
  • send_later(:your_method_name, -3, 3.days.from_now)
Jul 17 10

Summary of Web Application Libraries for iPhone

by dkberktas

PastryKit — it is from Apple, but it is not public,  you can see it from the iPhone User Guide, it will be released to public hopefully.

Sencha Touch — you should definitely see their kitchen sink, it is pretty cool.but there is no commercial license yet.

and the winner is ...

iUi — not that many people using it I guess. I build a site with it, if it is sth fast and easy to learn, iUi can do the job.

jqtouchdemos seem very nice, probably better than iUi in terms of current release capabilities and size of community.

iWebkitdemo seems promising, but not ready for prime time.

SproutCore — not for iPhone specificly, but its demo seems nice.

So my choice for the next task is jqtouch. not iui this time.

Jul 15 10

Using AWS S3 Service with RoR Paperclip

by dkberktas

Continuing from the last post, you might want to use AWS S3 for hosting the uploaded files. Actually the steps are pretty easy as described in the following links:

ps. If you are having an error like this

ArgumentError: wrong number of arguments (5 for 4)

this is probably because you have both the aws-s3 gem and right_aws, just change the environment.rb
as in the following link

http://stackoverflow.com/questions/1550708/rails-paperclip-conflict-between-aws-s3-gem-and-right-aws-gem-how-to-solve

ps2. If you are planning to deploy to heroku add the gem to .gems file, or you will get an error like this “App failed to start” — your application is missing the following gems:…

Jul 13 10

Paperclip and ImageMagick and a Weird Problem — in RoR

by dkberktas

As promised in the last post, here is the Paperclip and ImageMagick as an extension to railstutorial.

For image upload and manipulation, Paperclip seems to be the solutions. The following links does a great job of describing the installation process and basic usage, so I have nothing to add here.

So far so good, but if you are following railstutorial, you will probably doing this stuff to micropost, and you will probably get an error like this,

  1. “missing” image replacement in microspots
  2. In the log/development.log file,
ActionController::RoutingError (No route matches “/photos/original/missing.png” with {:method=>:get}):
Rendering rescues/layout (not_found)

Solution:

If you carefully inspect the log file you can catch the line

WARNING: Can’t mass-assign these protected attributes: photo
[4;36;1mMicropost Create (0.4ms)[0m [0;1mINSERT INTO “microposts” (“created_at”, “photo_file_size”, “updated_at”, “photo_file_name”, “photo_content_type”, “user_id”, “photo_updated_at”, “content”)

Just with just one line, open your model and fix the accessibility:

class Micropost &  ActiveRecord::Base
  attr_accessible :content, :photo
...

ps. In case you are a noob like me in RoR, this link shows howto uninstall the paperclip plug in.

ps2. Another possible problem might be your ImageMagick installation, make sure you have the correct path by trying convert and identify command. In case add the path to development.rb as described this Stackoverflow entry.

Summary of Steps to add Paperclip

  • script/plugin install git://github.com/thoughtbot/paperclip.git
  • script/generate paperclip product photo
  • In the model
has_attached_file :photo
  • In the form

header part

<% form_for @micropost do |f| %>
<% form_for @micropost, :html => { :multipart => true} do |f| %>

body part

<p>
<%= f.file_field :photo %>
</p>
  • To show the uploaded file
<%= image_tag @product.photo.url %>
Jul 13 10

Hello RoR

by dkberktas

Ruby on Rails (RoR) is the new framework I have been playing with and so far I should say it is really amazing. It has all these intuitive approaches that you find out by just guessing. I can only compare it with a couple of other technologies like RIFE (ogrence.net) and Grails (remotespots.com). RIFE has some neat features (template mechanism, web continuations, asynchronous mail queue, persistence layer, etc) but since the lead developer Geert Bevin stop actively developing it, it takes its place in the graveyard of dead tech. Then I try something different, Grails, which is a Groovy version of RoR. It is really good especially after Java Enterprise, convention over configuration is an excellent approach! But it is kind of very young, also Grails has this really fast development cycles, in a couple of month, I had to update my applications two times in which I spend hours to overcome plug-in dependencies, deployment issues, etc. ( one more thing, I can not find any other cool projects that uses Grails, even at SF Bay Groovy and Grails Meetup Group , actually I was the only one who is currently using Grails :-)  )

Since finding a good starter document is a very important decision, I took my time to select my first RoR source. I went over the following books and decided to use the latter one:

Although it is called as a tutorial, when you get the pdf dump, the 12 chapter tutorial is approximately 500 pages, which is literally a book.

The language of the book is very clean and most of the time funny. You can easily develop the code when you are reading it.  You can also follow a test driven approach if you want, but you don’t have (I didn’t).

I finished the book in 7 days with a daily 4 hours concentrated reading/coding sessions and with lots of Starbucks Misto (thanks Starbucks Besevler crew!).

The final code is at Github, and live demo site at Heroku.

As a pointer for the further steps, the tutorial suggest some pointers but I prefer to go on with my path, which requires ImageMagick and Paperclip, so next post will be about these two.

See you next time!

ps. I really like Heroku. Grails has something similar but to be honest, it is not that magical (as in iPad).

Jul 7 10

Yet Another Hacker News iPad Reader

by dkberktas

A couple of weeks ago, I wanted to read Hackernews with my iPad [although some HackerNews readers see iPad’s Safari good enough for the task (which requires opening new tabs for comments,  lots of copy & pasting URLs to share and  etc)], I searched for an application. Eventually, I found two, which are both paid applications. Since this applications is in my seven nights category (which is something I can code in seven consequent nights without disrupting my day work), I decided to code it myself.

After 3 nights the application was ready for the submission. It got rejected since I didn’t read the iPad User guidelines carefully (actually I just skimmed it in 5 minutes). The rejection reason is “You can’t show more than one popover at the same time”. I fixed the problem, and it is available in the app store (App Store link)

Yet Another Hackernews reader

I will probably change the default RSS feed of Hackernews which only show top 30 posts. Probably something on GAE, and maybe a simple my favorites kind of thing.

Jun 29 10

Grails 1.2.2 and Using ImageTools Plugin with a Slight Modification

by dkberktas

The Grails command create-controller and create-domain-class creates the files directly under the grails-app/domain and grails-app/controller, but the version(1.2.) I am using now has a different behaviour. Instead of grails-app/domain it creates grails-app/domain/{my-app-name}/ and grails-app/controller/{my-app-name}/

So I changed all the groovy file locations into a new folder(package) with my application name ( by the way all these are about my latest online usability testing tool Remotespots.com project). But something weird is happened with the ImageTools plugin. Since I move the controller files, ImageTool class is no longer visible to the controller that uses imagetool. Also, there is no way to import ImageTool since it is in default package, to solve this, go to .grails folder in your home folder and locate your projects folder and change the package of ImageTool.groovy as the following screenshot shows.

further information link

Jun 26 10

iPhone Ad Hoc Distribution Caveats and Useful Links

by dkberktas

One of the things I learn after developing a couple of iPhone (and iPad) applications is that sometimes it can take more  time to make it to app store or installing the app to the clients device than actually developing the applications.

Ad hoc distribution is one the things I really don’t like at all.

These are the caveats  :

-Download the distribution provisioning profile again from the Provisioning Portal, and remove the old one (from the organizer) before installing the new one

-Don’t forget to add the Entitlements.plist file with the key get-task-allow and the value false. (also add it tho the target build settings as Code Signing Entitlements key )

- If the client uses Windows make sure use .ipa file for sending the .app

- It is not iTunesArtwork.png but only iTunesArtwork

The links that explain the process:

  • http://johnehartzog.com/2009/04/iphone-app-ad-hoc-gotchas/
  • http://www.innerfence.com/howto/install-iphone-application-ad-hoc-distribution
  • http://www.iphonedevsdk.com/forum/iphone-sdk-development/3156-problem-iphone-ad-hoc-distribution.html
Jun 22 10

Java Dergisi

by dkberktas

Java Dergisinin ilk sayisini bir [KurumsalJava] grubundan duydum. Oldukca guzel bir girisim. — ozellikle, diger bilgisayar dergilerinin genellikle ayni icerigi tasimasi ve dergi olarak tuketilecek bir icerik sunmamasida dusunursek, bu dergi yazilim agirlikli olmasi ile beni oldukca heyecanlandird– Burda aklimdaki bir soruyuda hemen eklemem gerekiyor, basili dergiler daha ne kadar devam edecek cok merak ediyorum?

Java Dergisi dagitim olarak cok iyi bir is basarmis, neredeyse her yerde gormek mumkun. Derginin fiyati biraz yuksek(9.90) ozellikle Java ile ilgilenmesi olasi ogrenciler icin fiyat biraz hedef kitleyi dusurebilir. Derginin basim kalitesini dusurerek, dergi fiyatinda biraz oynama yapilabilir diye tahmin ediyorum, cunku kullanilan kagit cok cok sacma bir bicimde kaliteli. Guzel ornekler icin, bkn Matematik Dunyasi, Wired, NTV Bilim.

Yazilar korktugum gibi giris seviyesi tutoriallardan olusmuyor, gerci burada bir denge yakalamak cok zor, onlarca dali olan java dunyasinin hangi alanina girseniz bir uzmanlik alani cikiyor. Ornegin Java ME ve Androiddin arka arkaya yazilar ile islenmesi cok hostu. Biri gitmek uzere olan, biri yerlesmeye baslamis siki teknoloji.

Teknik yazilarin disinda, birazda genel havayi soluyan yazilarin eklenmesi derginin okuma keyfini arttirabilir, ornegin bu sayida James Gosling’in SUN’dan ayrilmasi ya da Oracle’in SUN’i satin almasi satir aralarinda gecistirilmis.

Son olarak, derginin Java dergisi olmasi illaki Java programlamasi ile ilgili olmasini gerektirmez. JVM ustunde calisan diger dillerden de bahsedilmesi (jruby, jython, scala, groovy) ve bunlari kullanan frameworklerin tanitilmasi da bence onemli bir katki olur.

Umarim dergi yeterli satis rakamlarini saglar ve surekliligi saglayabilir.