Wednesday, 30 May 2012

active record update_all class method

Hi,

Here is the method in Active Record that updates all records. You can update records based on condition also.


update_all(updates, conditions = nil, options = {})

ex:
1) Updating all user records with status to active

    User.update_all(:status => 'active')

    This will return the records count that were updated.


2)  Updating records based on condition
   
     User.update_all(:status => 'active', ['title like ?', 'uma'])





Thank You,
Uma Mahesh.


 

ruby on rails resources

Hi,

Here is the list of all books related to ruby on rails.

http://pinterest.com/pvnrtmol/ruby-and-rails-resources/

Blog: http://rorguide.blogspot.in/


Thank You,
Uma Mahesh

Sunday, 27 May 2012

Rubymine usage and tips

Hi,

Here are few steps which can help you on using the rubymine.

Ctrl+Shift+Backspace (Navigate | Last Edit Location) brings you back to the last place where you made changes in the code.
Pressing Ctrl+Shift+Backspace a few times moves you deeper into your changes history.


Use Ctrl+Shift+F7 (Edit | Find | Highlight Usages in File) to quickly highlight usages of some variable in the current file.
Use F3 and Shift+F3 keys to navigate through highlighted usages.
Press Escape to remove the highlighting.


To see your local history of changes in a file, invoke Local History | Show History in the popup menu. You may navigate through different file versions, see the differences and rollback to any previous version.
Use the same popup menu item to see the history of changes on a directory. You will never lose any code with this feature!


Ctrl+E (View | Recent Files) brings a popup list of the recently visited files. Choose the desired file and press Enter to open it.
Besides recent files, you can easily bring up the results of the usage searches that you have performed recently. To do that, use the same Ctrl+E shortcut with the Find tool window having the focus, and select the desired find usages result from the Recent Find Usages popup.


Use Alt+Up and Alt+Down keys to quickly move between methods in the editor.

Use the Ctrl+Shift+V shortcut to choose and insert recent clipboard contents into the text.


The shortcuts such as Ctrl+Q (View | Quick Documentation), Ctrl+P (View | Parameter Info), Ctrl+B (Navigate | Declaration) and others can be used not only in the editor but in the code completion popup list as we

To open any particular method or field in the editor quickly, press Ctrl+Alt+Shift+N (Navigate | Symbol) and start typing its name.
Choose the symbol from a drop-down list that appears.

Use Alt+Shift+C to quickly review your recent changes to the project.


With a single keystroke, you can apply another code style/coloring scheme or keymap right from the editor. Just press Ctrl+Back Quote (View | Quick Switch Scheme), to specify the scheme you want to change.


Thank You,
Uma Mahesh

Friday, 25 May 2012

ruby on rails blogs

Hi,

Here is the list of blogs that I have found useful information about ruby on rails with clear explanation about the topics and they helped me alot on many situations

> Ruby basic concepts : http://blog.joshsoftware.com/



Best file comparision utility or tool

Hi,

In the application/project development we may have situation where we need to compare the two similar files to know what changes have been made in them.

I have used recently one of the best tool to compare files and folders and which made easy for me while integrating the code while working with multiple developers on same project.

Here is the tool:  Beyond Compare

Its a tool where we can compare two files or folders with the same and name and it shows the difference of code/text by comparing them. We can also push the newly added code from one file to another with same just by single click.

You can download the software form here.

Download Beyond Compare


Thank You,
Uma Mahesh.

Thursday, 24 May 2012

Count relation between models in rails using counter_cache option

I have a User with has_many articles. In order to display(count) number of articles created by user I will call @user.articles.count.
It will internaly run sql query on articles table. In order to eliminate the external query for displaying the count(i.e number of articles) active record associations provides usefull option for that.


Say a User has_many articles. In the articles model, add a line blongs_to :user, counter_cache: true. Add an integer column to the user table named articles_count. Whenever you create a article, the counter will be updated. See http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-belongs_to (:counter_cache section).

:counter_cache
Caches the number of belonging objects on the associate class through the use of increment_counter and decrement_counter. The counter cache is incremented when an object of this class is created and decremented when it’s destroyed. This requires that a column named #{table_name}_count (such as comments_count for a belonging Comment class) is used on the associate class (such as a Post class). You can also specify a custom counter cache column by providing a column name instead of a true/false value to this option (e.g., :counter_cache => :my_custom_counter.) Note: Specifying a counter cache will add it to that model’s list of readonly attributes using attr_readonly.


Thank you,
Uma Mahesh

Wednesday, 23 May 2012

ruby on rails coding standards

Hi,

Here is the good resource where you can learn ruby on rails coding standards.

https://github.com/bbatsov/ruby-style-guide

The above guidelines have been followed by github team while developing the github application in ruby on rails.

Follow the below standards to have good style of code.

https://github.com/bbatsov/ruby-style-guide

Thank You,
Uma Mahesh.

Monday, 7 May 2012

rails different datatypes in different databases

Here are the list of datatype that can be used in rails migrations and its respective database support types.


How to hide filters in the active admin view

Hi,

I am working with active admin customisation for one of my project. In that I need to hide the filters in the list views.

This can be done with simple configuration as shown below

ActiveAdmin.register Product do

config.clear_sidebar_sections!

end

The above configuration will make filters not to display in the list view.

Thank You,
Uma Mahesh

How to hide API & Downloads links in the active admin

Hi,

I am working with active admin customisation for one of my project. In that I need to hide the API & Downloads links in the list views.

I have searched for it making it configurable at controller level. But I came to see there is no such provision.

By goggling I found solution as this can done through css path. I.e making the css class for that text to be hide.

Here is the style that need to be added in the active admin css style sheet.

In app/assets/stylesheets/active_admin.css.scss

.index #active_admin_content #index_footer {
  color: white;
  a {
    display: none;
  }
}

This will make the download links hide in the view.

Thank You,
Uma Mahesh.

Tuesday, 1 May 2012

What is the future of Ruby on Rails developer ?

What is the future of Ruby on Rails developer ?

 

Here are the list of answers I came across in social networking sites. 

 

Andrew McElroy  I think JavaScript is going to be the new 'rockstar'. I can forsee a rails 4.3 or 5.0 version which essentially compiles all the ruby code down to javascript and in essence eats nodeJS' lunch. It is already possible to execute javascript in ruby context. Also, it is possible though a different library to go the other direction. Clearly, Javascript is seeing a lot of attention these days. One more prediction, CoffeeScript doesn't so much go away as become merged into a future ECMAScript.
It's worth pointing out that with the inclusion of the asset pipeline in rails 3.1, you must now have a Javascript Runtime engine on the server side. Currently therubyracer gem seems to be the most popular. I think this dependency is a pretty telling future indicator.

One thing is for certain, a future rails app will be expected to have a server side model2 (what we normally in rails think of MVC) structure, and the client side will have its own true MVC be it angularJS, Backbone, EXT, etc.

It will be interesting to see where all this goes.

TL;DR: ruby has a future, maybe within the execution context of JS, but it isn't going away.

 

 

 

 

Nathan Van der Auwera  I see on the one hand that rails is still growing. More and more companies are switching to rails. Rails has the advantage that server-code and views are prepared in ruby: one language one platform. 

But, in practice, to get a snappy-feeling website, you already had to do a lot of javascript.

Now, with frameworks like Backbone.js/spine.js/ember.js/batman.js ... we move to a bigger client, a cleaner server. Rails will still have it's place, with the asset-pipeline and such. But on the other hand sites will do more smaller requests. So I think a server like node.js then is becoming very interesting. 

I definitely think you should learn these, just to know it's strengths and weaknesses. 

Looking further down the road, i think haskell with a webserver like yesod/warp is also looking very promising.

 

 

Rogier Svensson Krona  As said before future is never known. However besides the technical side I would like to add some comments on the business side. Rails is very community driven (at least in Scandinavia) and that somehow means that there is less activitity on the business side. While Java and many other tools, languages, frameworks etc. is "familiar as words" even for the decisionmakers of established companies, Rails is quite unknown. I think Rails has to be more exposed to these companies or else there is a risk that we get stuck in startup companies and I don´t think that´s enough even if many of them grow. This might not have much to do with the future of the Rails developer, they can switch to something else that is better, or more established on the market. 

But as usual, I might be wrong, it happens :-)
  

 

 

Lets share your thoughts...

 

Thank You,

Uma Mahesh.

 

 

Deploying static website on Heroku.

Hi,

Some times we may have static page website with three to four html pages. We can use heroku for deploying static websites also.

Heroku uses Rack app for this.

Here are the steps that need to be taken for creating the static website in heroku.

Your folder should be organised like this:

- MyApp
  |- config.ru
  |- public
    |- index.html
    |- stylesheets
    |- images


In config.ru file add the following:

use Rack::Static,
  :urls => ["/stylesheets", "/images"],
  :root => "public"

run lambda { |env|
  [
    200,
    {
      'Content-Type'  => 'text/html',
      'Cache-Control' => 'public, max-age=86400'
    },
    File.open('public/index.html', File::RDONLY)
  ]
}


And there you go, a static site being served on Heroku completely cached and easily served using a single dyno.

To know more information about this check the heroku website: https://devcenter.heroku.com/articles/static-sites-on-heroku

Thank You,
Uma Mahesh.

writing story for a ruby on rails application

Hi Developers,

Before starting any application we need to write user stories as the part for BDD development.

Depending on the way you write the user stories, You will have the outcome of the application and itself shows does your application was healthy product or unhealthy product. So be clear while writing the user stories.

I have seen a blog where they have shown the difference between healthy code and unhealthy code and the things that neede to be taken care while writing the stories.

Here is the url : http://blog.hashrocket.com/posts/writing-the-story-of-an-application

Opensource project management in ruby on rails


Opensource project management.

I have recently heard about the new open source project management too in rails. If any one worked on it, please share your experience and suggestions on using it.

ChiliProject is a web based open source project management system.

It provides a good interface for managing the complete project life cycle.

The official website for chilliproject https://www.chiliproject.org/

Download Chilliproject : https://www.chiliproject.org/projects/chiliproject/wiki/Download

Thank You,
Uma Mahesh.