Rails 4 is released. Lots of new features has been added to rails. Here we will see what new directories have been added.
We will create a sample app in rails 4 so that it will be easy to see the new structure. I am assuming you have updated your rails. To check current version of rails run following command:
It should be Rails 4.0.0
Now create a very simple rails application
It creates a our app directory . You will see there are some new directories and files. Lets go to each one by one
In this directory there is new concerns/ dir under controllers/ and models/. Concerns are added to manage your models/controllers in a better way .
Mixins and modules code can be put under this dir. Lets say in our blog application we have user model and post model and we require to add comments for both model so we created a commentable module in our concerns/ dir and included in both model.
1 2 3 4 5 6 7 8 9 10 11 12
Now suppose we need to add one more module noteable to our model post.
1 2 3 4 5 6 7 8 9 10 11
But we can also include Commentable to Noteable.
1 2 3 4 5 6 7 8 9 10 11
Because of line “extend ActiveSupport::Concern ” both Commentable and Noteable are accessible for Post class.
Its easy to cross sharing of code among models and to make your model clean.
App executables bundle, rails and rake are under this dir. So dont need to run ‘bundle exec’ before any rails command. Binstubs can also be generated using bundle command ,bundle 1.3 added spports for generating binstubs. What Binstubs are executables required to prepare the environment before original executable.
When we do
an executable file is genearted in gems//cucumber-1.3.2/bin dir(i am using rvm here)
Now we can generate using budnle command
It wil genrate executable in bin/. Having executables within your app ensures that they are using app ruby and gems.
We use config.filter_parameters in config/application.rb to filter out parameters which we dont want to show in log files. But Its moved to filter_parameter_logging.rb under initializers dir
Lets say we have an attribute customer_id of customer model and we want to filter in our log files then just write
After restarting your server if there is any request having customer_id parameter. it will not show the value of customer_id
Doc has been removed from rails directory. Its is extracted in sdoc gem and added to Gemfile by default so still you can generate docs by running following rake task
It has been removed and rails executable is moved to bin/ dir
This directory has been changed quite a bit.
Now we have controllers and models in place of functionals and units
We also have helpers and mailers dir under test by default
Performance test has been extracted to a new Gem. So performance dir is not under test by default
Corresponding rake task for test has also changed –:
1 2 3 4
Rails plugins are already gone away so this dir is no more needed.
Our favorite rails command ‘scaffold’ gives us few new files. Lets create new scaffold
You will see there are two new files
I hope this post will be useful for you. If there is any mistake in this post just let me know.
There are lot to learn about rails 4. If you want here are some links