Archive for category Open Source Technologies

10 Reasons why – Ruby on Rails

10 Reasons why – Ruby on Rails

Your development team has been frustrating you, projects start and four weeks later the development team is still developing the framework, your budget is running out. You want productivity but just don’t know how to get it. Is there an answer? One of your developers keeps mentioning this great framework called ‘Ruby on Rails’. Is this the answer? This article discusses the positives and the negatives in moving to this new technology.

1. Ruby on Rails provides a consistent approach to building web applications with an out of the box architecture. Traditionally starting a new web application is a fairly heavy weight process, you typically need to survey and choose your various software components to solve the common architectural problems of persistence, logging, build scripts, application configuration, web tier components and workflow. With the Rails framework these decisions are already made for you, so you can get on to understanding the business problem and quickly build a working system. You become productive in minutes not weeks or months.

2. In a Rails application, a pragmatic philosophy of convention over configuration is taken, this is apparent in all layers of the architecture with the highest productivity gains noticeable in the relationship between the model and the database. Once the developer understands the rules and constraints, Rails magically connects your view to your controller and model, and your model to the database. You don’t need generators or specialised tools to manage this, it all just works.

3. Unlike other productive web scripting languages, Ruby is a fully featured object-oriented language. Ruby also adds additional power with mix-ins modules which contain independent code to inject into your classes, blocks and closures simplifying client code behaviour. Its dynamic nature gives it power beyond static languages such as .NET and java, and the benefits are apparent by how the Rails framework has been put together itself.

4. Unlike other web templating technologies, the templating technology built into Rails can be used to generate web pages, emails, xml documents or any text document that requires dynamic content.

5. Rails includes a well thought out object relationship mapping tool, ActiveRecord, which provides your answer to database persistence. Your model is seamlessly persisted to the database. Transactions, inheritance models, validation, and caching have all been thought out and are production ready. With Rails you become a lot closer to the structure of the database than traditional object-oriented development methodologies. This is a good thing as over time as the database will no doubt end up being your project’s most valuable asset.

6. Rails includes support for a variety of web technologies. Every web application needs email integration at some point and Rails provides an out of the box smart solution, and as with other Rails technologies it gives you the complete package down to configuration in development, test and production environments. Ruby on Rails also supports web services, the integration with Rails due to the dynamic nature of Ruby is simply, clean and seamless. If you are moving into the Web 2.0 space, Rails provides a rich abstracted interface to implementing AJAX operations.

7. Generally software projects do not mature if at all to the point of having a solid foundation to perform database migrations and rollbacks between environments and across development systems. However with the Rails framework you will be delighted with the implementation of database migrations for applying and rolling back database changes. You enter your update and rollback scripts in Ruby, Rails understands the current version and can move forwards or backwards to any database version.

8. For development productivity, the shorter the gap between the change and test cycle the better. In Rails, changes are reflexed immediately within the runtime environment so developers can quickly iterate between fix and test cycles without any expensive redeploys. Ruby code is also easily testable. Methods and objects can be replaced at runtime so software components can easily be tested without resorting to external tools or generators.

9. Getting started with Rails is easy as generators will propel you along. An experienced Rails developer will also become aware of numerous idioms available within the Rails framework that shared the amount of code a developer need write. Overall less code to write means lower complexity, higher productivity and less bugs.

10. Ruby has been around for a long time, the Rails framework which has deservedly propelled Ruby into the spotlight has hit version 2.3 and is not only production ready but now well supported in the community and a stack of resource available on the web. Ruby and the Rails framework is open source and well supported by a clever team of contributors.

*So what are some of the cons?*

1. If you take time to follow the Ruby examples and tutorials it may give you a false sense of productivity. They typically follow the formula of creating a database model, configuring a connection to the database and joining it up to the model controller and view by use of the generators. This is all very simple involving a dozen or so lines of code. In the real world however you will be working at higher level of complexity and will need to understand multiple facets of Ruby and the Rails framework to be productive in churning out business functionality. You will need to invest in getting up to speed with the language and framework. As Ruby is a dynamic language, more automated testing is required. Your developers will need to become more disciplined and rigorous in creating unit tests as part of their development process.

2. If the type of development you are doing is glueing together existing systems or building back end systems, be aware that Rails is optimized for building web applications, your host system or enterprise database may not have the integration module you require for Ruby UPDATE (2010) – however JRuby is now maturing and can plug the gap by leveraging legacy java libraries and provide a lower cost to more enjoyable path to legacy integration. DSL’s can be engineered to remove the laborious code java developers are use to writing.

After considering the pros and cons, my advice would be that if your business or application has tight timelines, you want a more powerful web application for your buck with alone with inbuilt tools which remove the pain and setup cost of an IT project to seriously suggest considering investment into the Ruby on Rails framework.

No Comments

ERROR: rvm requires autoreconf to install the selected ruby interpreter however autoreconf was not found in the PATH.

This problem generally occurs in 1.8.7-head

In ubuntu this can solve your problem.

 

apt-get install automake

1 Comment

uninitialized constant Rake::DSL

what will we do when we get error–uninitialized constant Rake::DSL

at the time of rake db:create

add    require ‘rake/dsl_definition’  above require ‘rake’  in your rakefile

No Comments

Convert utf-8 to chinese in ruby on rails

Sample code to send a utf-8 string in subject line of email. Its pretty simple and straight forward

 

def send_to_lead(lead_email, from_email, from_name, offer_id, club_id, customer_id)
@customer_name = from_name
@customer_email = from_email
str = “期待很快就可!”
#    str= “subject in english”
subject=str
if str[0..1]==”&#”
subject_raw = str.gsub(“&#”,”").gsub(“!”,”").split(“;”)
subject=”"
subject_raw.each {|t| subject += [t.to_i].pack(“U*”)}
end
mail(:to => lead_email,
:from => “\”"+from_name+”\”" + “<”+from_email+”>”,
:charset => ‘utf-8′,
:subject => subject,
:reply_to => ‘noreply@buddyreferralsystem.com’,
:content_type =>’multipart/alternative’,
:content_transfer_encoding => ’8bit’,
“X-Mailer” => “Ruby (1.9.2)”
).deliver
end

No Comments

Rails ActionMailer STARTTLS bug solution

This is a common rails mailer issue and bug new programmers,

Net::SMTPAuthenticationError in InviteController#send_email_invites

530 5.7.0 Must issue a STARTTLS command first. u10sm46215072pbr.12

the solution of this problem is to include following settings in your environment.rb file
config/environments/development.rb
-----------------------------------
    require 'tlsmail' #key but not always described
    Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)   
    ActionMailer::Base.delivery_method = :smtp
    ActionMailer::Base.perform_deliveries = true
    ActionMailer::Base.raise_delivery_errors = true
   
    ActionMailer::Base.smtp_settings = {
      :enable_starttls_auto => true,  #this is the important part!
      :address        => 'smtp.gmail.com',
      :port           => 587,
      :domain         => 'xtargets.com',
      :authentication => :plain,
      :user_name      => '-------',
      :password       => '-------'
    }
   

No Comments

Difference between ‘sudo’ & ‘su -c’ commands

Hello everyone,

For those who are interested, i would like to highlight the differences between using ‘sudo’ and ‘su -c’ commands.

Although, it will be applicable to all linux distributions, in this blog i am going to concentrate on Ubuntu & Fedora.

1) Required Password:

  • ‘sudo’ requires current user password.
  • Whereas, ‘su -c’ requires root user password. (This is no coincidence. Infact, this was the very reason for introduction of sudo command).

 

2) Operational Speed:

  • ‘sudo’ command is slower in operation as compared to ‘su -c’ command.
  • (In the normal course of action, you might even not notice it. But, try using it over SSH or for SE-Linux like operations, you will notice the difference.)

 

3) It’s working:

  • On issuing the ‘sudo’ command, os checks the sudoers file in /etc directory for a flag which tells is whether or not root like permission should be given to current user.
  • On the other hand, when ‘su -c’ means, switch to super user(root) and -c switch says, only for this command.

 

4) Time Duration:

  • Since, ‘su -c’ command elevates permission for only specified command, you need to enter root password, each time it is used.
  • Whereas, on entering password for sudo command, it gives root like permissions for about 5 minutes. i.e. you don’t need to enter password again if you issue sudo command again.

 

I sincerely hope you liked it. Please leave your valuable comments and suggestions.

, , , , , ,

1 Comment

Install pure-ftpd & restrict users to their home directories (Fedora/openSuse)

Hello everyone,

Steps to install pure-ftpd and jail users:

Note-1) On typing ‘ftp localhost’, if you get “Install command ‘ftp’ to provide command ‘ftp’? [N/y]” error message, don’t worry that perfectly normal.  Simply type y. This is “ftp client binary”, whereas vsftpd is “ftp server”.

Step-1) To install pure-ftpd, on the terminal type:
        su -c ‘yum -y install ftp pure-ftpd’

Step-2) To jail users to their home directories, on the terminal type:
        su -c ‘[nano/vi/emacs] /etc/pure-ftpd/pure-ftpd.conf’
        Search for text “ChrootEveryone” and change it’s value to “yes”.

Step-3) To allow local users to login, on the terminal type:
        su -c ‘[nano/vi/emacs] /etc/pure-ftpd/pure-ftpd.conf’
        Search for text “UnixAuthentication” and change it’s value to “yes”

Step-4) Restart service:
        su -c ‘service pure-ftpd restart’

Step-5) If you skip this, you will get “500 OOPS: cannot change directory:/home/user_name” error when you login to ftp server.
        su -c ‘setsebool -P ftp_home_dir on’

    Congratulations! you have successfully jailed users to their respective home directories.

Step-6) To test, on the terminal windows type:
        ftp localhost
        (when prompted, enter local computer login credentials)
        pwd
        ls -lh
        ls -lh ../../.. OR whatever you want to check.

 

I sincerely hope you liked it. Please leave your valuable comments and suggestions.

, , , , ,

2 Comments

Install pure-ftpd & restrict users to their home directories (Ubuntu)

Hello everyone,

Steps to install pure-ftpd and jail users:

Step-1) To install pure-ftpd, on the terminal type:
sudo apt-get -y install pure-ftpd

Step-2) To jail users to their home directories, on the terminal type:
        cd /etc/pure-ftpd/conf
        sudo touch ChrootEveryone (Note: Please type the name as it is. It’s case-sensitive.)
        sudo [nano/vi/emacs] ChrootEveryone
        type ‘yes’ in the file, save and exit.

Step-3) Restart service:
        sudo service pure-ftpd restart

    Congratulations! you have successfully jailed users to their respective home directories.

Step-4) To test, on the terminal windows type:
        ftp localhost
        #(when prompted, enter local computer login credentials)
        pwd
        ls -lh
        ls -lh ../../.. OR whatever you want to check.

 

I sincerely hope you liked it. Please leave your valuable comments and suggestions.

, , , ,

No Comments

Install vsftpd & restrict users to their home directories (Fedora/openSuse)

Hello everyone,

Steps to install vsftpd and jail users to their home directories:

Note-1) On typing ‘ftp localhost’, if you get “Install command ‘ftp’ to provide command ‘ftp’? [N/y]” error message, don’t worry that perfectly normal.  Simply type y. This is “ftp client binary”, whereas vsftpd is “ftp server”.

Step-1) To install vsftpd, on the terminal type:
su -c ‘yum -y install ftp vsftpd’

Step-2) To edit vsftpd configuration file, on the terminal type:
su -c ‘[nano/vi/emacs] /etc/vsftpd/vsftpd.conf’

Step-3) To jail users to their respective home directories, search the file for text “chroot_local_user” and remove the ‘#’ pound sign at the begining of the line and change it’s value to ‘YES’. Save and exit.

Step-4) Restart vsftpd service:
su -c ‘/etc/init.d/vsftpd restart’

Step-5) If you skip this, you will get “500 OOPS: cannot change directory:/home/user_name” error when you login to ftp server.
su -c ‘setsebool -P ftp_home_dir on’

    Congratulations! you have successfully jailed users to their respective home directories.

Step-6) To test, on the terminal windows type:
        ftp localhost
        (when prompted, enter local computer login credentials)
        pwd
        ls -lh
        ls -lh ../../.. OR whatever you want to check.

 

I sincerely hope you liked it. Please leave your valuable comments and suggestions.

, , , , , ,

No Comments

Install vsftpd & restrict users to their home directories (Ubuntu)

Hello everyone,

Steps to install vsftpd and jail users to their home directories:

Step-1) To install vsftpd, on the terminal type:
sudo apt-get -y install vsftpd

Step-2) To edit vsftpd configuration file, on the terminal type:
sudo [nano/vi/emacs] /etc/vsftpd.conf

Step-3) To jail users to their respective home directories, search the file for text “chroot_local_user” and remove the ‘#’ pound sign at the begining of the line and change it’s value to ‘YES’. Save and exit.

Step-4) Restart vsftpd service:
sudo service vsftpd restart

Congratulations! you have successfully jailed users to their respective home directories.

Step-5) To test, on the terminal windows type:
ftp localhost
        (when prompted, enter local computer login credentials)
        pwd
        ls -lh
        ls -lh ../../.. OR whatever you want to check.

 

I sincerely hope you liked it. Please leave your valuable comments and suggestions.

, , , , ,

No Comments