If you have a certain type of policy for not allowing users of all ages to use your services, or simply want to find the age of your users, then you can do it pretty easily and elegantly in Rails. Continue reading
Page 31 of 55
You may need attributes in your views or in your JSON response which may not be part of your models. In these situations, you may use virtual attributes that you may only use in your particular cases, and not bother to add many new attributes in your database table that are not that much relevant for that model.
GitHub is one of the best places for developers to store their projects, collaborate with other colleagues, and learn from other open source projects as well. These type of projects are written in different programming languages, usually using different frameworks. As these frameworks or developers in general usually possess certain ways of organizing their code files into many folders, it makes it a bit difficult to navigate through them manually in GitHub. Luckily there is a really helpful shortcut that help with that. Continue reading
One of the best practices is keeping your controllers with as little code as possible, and have all the validations in the models. Rails includes a lot of validations that you can use in your models, and many other helpers that help you focus on your business logic and develop your projects as quickly as possible. A helper method that is among the unpopular ones is the possibility to check the old value of an attribute of a object, before doing any database transaction.
One of the best JavaScript libraries for working with dates is moment. It is really easy to install, use and has many functions that help you with parsing, validating, manipulating and formatting dates.
Rails gives you a lot of great ways for rapid development, but there comes a time when your application is already mature and needs to be optimized, because it has become slow. The more gems you add to it, the slower it tends to get. Each gem you add in your project will increase the level of RAM this app consumes. Here is a gem called derailed that can help you learn about other gems, developed by Richard Schneeman.
Globalize is one of the most famous gems that is used for translating dynamic content in Rails application. It is really easy to use, and brings a lot of conveniences immediately after you add it in your application. I recently had to do a more complex query using the table added by Globalize generator, and I could not find that much information about ways of doing joins for this newly added table with the one that it corresponds and that translates its attributes. In this article, you can see a short example on how to do that.
There can be cases where you wished you named that controller a lot better, as it does not make any sense and is very ambiguous in its current form. If you have ever wondered whether there is a way for you to do quick renamings of multiple related files inside a Rails project, then I have some good news for you. There is already a gem called Rails Refactor, that can be used to do these renamings. Continue reading
In the last post, we saw how we can translate a variety of dynamic contents that we may have in our Rails applications using globalize gem. There is another complementary gem to globalize that can be used to do these translations inside Rails Admin, which make it a lot easier and simpler to insert these translations inside RailsAdmin’s user friendly interface.
We are in an interconnected world, where people across the planet can use the projects that we develop, and having the opportunity to offer them with additional international languages make them a lot better. We can obviously use locale for doing the translations of static strings like labels, or placeholder descriptions that appear across our applications, so we should also have something that can give us a way to translate the dynamic content. There is a really great Ruby gem that makes the translation of model attributes a lot easier. This gem is called Globalize and is very easy to use.