19/11/2016
Published my first Gem which adds searching functionality to active recordĀ modelsmake_model_searchable adds simple searching functionality to active record models. No need to implement same search function for each model every time! What is does? Provides modular solution to add search functionality for selected fields. It let’s you specify which fields you want to make searchable adding searchable_attributes in model. If no field is specified, all attributes are searched. What’s next?
There are many improvements to be made, such as adding support for allowing to search joined associations, ability to search from numeric and date fields, and few more.
JSON is favorite format for exchanging data between server and client developers. Rails provides support for rendering proper JSON response, making it easy to focus on core functionality of application. Here are few things I learned to create clean, customized response.
Suppose we have a User model with fields such as first_name, last_name, picture, age, authentication_token, password_digest and timestamps fields such as created_at and updated_at. Using render json: @user will convert user object to json by calling “to_json” method of user for you.
Generated response contains all fields of our User model, including authentication tokens, password digest, timestamps or other sensitive information related to user which should not be permitted in response.
To prevent such information from being sent I used to prepare customized json responses by logic related to rendering inside of helper classes and controller actions. That approach just increased redundancy, inconsistency, inefficiency and was harder to maintain. Luckily, soon I got introduced to concept of overriding “as_json” method. Earlier this month when I posted an article about using github pages to host personal website, I added a contact form, beautified it with bootstrap and decided to ignore how would I handle form submissions and keep track of responses. But soon I realized my mistake when someone excitedly asked "Did you get my message I submitted through contact form?". It was disappointing, but I had to say I didn't handle it, yet. So here is how I handled 'it'. Github pages provides support for static pages and that makes handling forms on static website a bit tricky. Turns out, capturing data from forms such as contact form in static website is super easy, with little or no configuration needed. There are many free and paid services available according to your requirement. Initially I tried one open-source service formspree, and then for better control I used Google Apps Script. First approach: FORMSPREE It's absolutely simple approach, no configuration is needed in your code. Here's is what you do:
Go to https://formspree.io/ and follow steps as mentioned in website. Just don't forget to add 'name' attribute to your each input field of your form. Here's what your form would look like after mentioned changes. Look closely at added name fields in html form. email field with '_replyto' is important to capture email id of person who submitted form. Last week I built my portfolio website which I wanted create from a quite a long time. After few iterations when I was happy with result, I decided to go with github pages for hosting my website. Github provides one personal website per account, and one for each of your project. Here's a link of github pages which walks you through how to do that in few easy steps. Visit my website, https://8parth.github.io/ and feel free to give your feedback and suggestions as it will make it more better.
For hosting personal website with github,
You can do much more than just hosting static pages by using jekyll. Few months back while experimenting with github pages I tried to use jekyll. Jekyll requires knowledge of ruby on rails. Gaya is one cool jekyll responsive theme for jekyll which you might try if you need to host something like blog via github. Hope you enjoyed and might find interesting. Thanks and feel free to share your thoughts. Recently I used Rspec to implement Test Driven Development(TDD) approach for developing an existing rails application. After setting up test environment it was time to migrate data from development database to test database in order to test some controller actions. There are some neat ways to use 'factories' or 'fixtures' but that wasn't right choice due to size factor. Taking dump of database and restoring into test db, well that's quick and easy solution but I didn't want data of all tables. I was searching for a better solution and I found one. I used rails console to migrate data from development environment to test environment. Here's what rails guide has to say about rails console: The console command lets you interact with your Rails application from the command line. On the underside, rails console uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website. Git is widely used version control system for managing source code and enhance collaboration. Most important thing to take care while working with git is that you must be aware of branch you are working on, so that you don't accidentally make changes in wrong branch of your repository. This tricky in terminal as it doesn't show git branch name. We can customize terminal in such a way that it shows current branch name of repository you are working on and reduces chances of making changes to wrong branch to great extent. Here is how to do that: Open bashrc file. Uploading file to amazon S3 requires following steps:
I am assuming you have already set up your aws account and IAM users account. If you have not installed AWS Toolkit for eclipse yet, you refer to this link. Now we start the process of uploading file to aws S3 storage service. 1. create an upload form in jsp with form action as controller name. Here, UploadVideoController is name of our controller. When you use <input type="file"> element, you need to add enctype = "multipart/form-data" attribute to form tag. enctype attribute's "multipart/form-data" allows entire files to be included in the data. accept="video/* restricts files to be selected in video format. |
AuthorHi, I am Parth Modi. I am software developer. I like to work in Ruby on Rails and Java. Archives
October 2016
CategoriesAll Aws-tutorials Git Github Pages Json Linux Rails API Ruby Ruby On Rails Tutorials |