Arun Agrawal’s Blog

Ruby on Rails Developer

Receiving Emails in Rails3

To receive email you have to write a method which needs to public in any subclass of ActionMailer::Base. The name should be receive. The method receive. will take a argument which is a Mail::Message obejct. An example here :
class EmailReceiver  < ActionMailer::Base

  def receive(email)
    person = Profile.find_by_email(email.to.first)
    person.emails.create(
      :subject => email.subject,
      :body => email.body
    )
  end
end
You can invoke this method on Mailer class to handle incoming email. You don’t have to implement the receive class method yourself, it is inherited from ActionMailer::Base.

Bundler

Bundler is a preferred way to manage your Rails application gem decencies. In Rails3 the bundler comes by default. Gemfile is the place where we need to tell about our gems. Example file looks like
gem "rails", "~> 3.0.1"
gem "mongo", "1.1.5"
gem "bson", "1.1.5"
gem "bson_ext", "1.1.5"
gem "mongoid", :git => "http://github.com/mongoid/mongoid.git"
gem "devise"
gem "haml"
group [:test, :development] do
 gem 'ruby-debug'
end
group :test do
 gem "rspec", "~> 2.0.0"
 gem "rspec-rails", "~> 2.0.0"
 gem "shoulda"
 gem "factory_girl"
 gem "faker"
end
Here we can define number of groups according to our environments. As you can see above example ‘ruby-debug’ will only get loaded when you are in development and test environment. ‘rspec’, ‘faker’ will gets loaded in test environment only. So this is a cool way to manage your gem dependencies. And ‘rails’, ‘mongo’, ‘bson’ all other ungrouped gems gets loaded in all environment.

Active Record

An object that wraps a row in a database table or view, encapsulate the database access, and add domain logic on that data called Active Record. Active record object carries both data and behavior. The data structure of the Active Record should exactly match that of the database: one field in the class for each column in the table. In Rails Active record comes by default as in terms of models. Active Record class contain some method which perform like :
  • Implement some pieces of business logic
  • Construct an instance of the Active Record from a SQL result set row
  • Update the database and insert into it the data in the Active Record
  • Get and set the field values
Active Record works very well when domain logic is not too complex.

Praise for Agile Product Management With Scrum

“Product owners have had few places to turn to for advice, despite having the hardest role on an agile project. This book rectifies that. Roman Pichler’s insights into the duties of the product owner are powerful and practical. Correctly applied, his advice will benefit any product owner and agile team.” —Mike Cohn, Author of Succeeding with Agile, Agile Estimating and Planning, and User Stories Applied “Scrum is silent on how a product owner can maximize value. Most product managers and marketers don’t know how to use the iterative, incremental nature of Scrum to do so. Roman has filled this hole nicely with his new book, Agile Product Management with Scrum.” —Ken Schwaber, codeveloper of the Scrum process “With so little written on the intersections of agile methods and product management, Roman makes a significant contribution to the field. The book provides clear guidance and rich examples on how to become an agile product manager and a successful product owner, and, further, how to lead with a strong vision. This book is a must read for product managers new to Scrum, product owners new to product management, and any product manager who wants to get the most out of Agile.” —Greg Cohen, Principal Consultant, 280 Group and Director, Silicon Valley Product Management Association “I’m always happy to hear what Roman is thinking. What I really like about this book is that he not only shares his experience (“Common Mistakes” is a great section), but he also brings in the wisdom of others in the field. This powerful combination allows him to see farther ahead and share that vision with us. Thanks, Roman!” —Linda Rising, Independent Consultant and coauthor of Fearless Change: Patterns for Introducing New Ideas