Tagged: rails
Setup rails to return json responses in json5 format
My project is in Rails 5, and I was following this tutorial to setup my rails with JSON5 responses. Turns out things have changed a bit. If you want to avoid the strange deprecation...
ActiveModel Serializer converts underscores to hyphens
Here’s the problem I ran into. I setup rails in the API mode and configured to use ActiveModelSerializers and follow the JSON5 spec. But turns out, that converts all the field names in my...
How to run only one test in rspec
Mostly while developing its extremely convenient to be able to run just one particular describe block or it block. Rspec lets you do that using a combination of focus: true as well as adding...
How to generate a model serializer using active_model_serializer gem
If you are using the active_model_serializer gem, you can generate Model serializers using the following command. rails generate serializer <model_name> # e.g. rails generate serializer user
How to test a private method in rspec
Since you cannot access a private method directly, in order to test a private method, you can make use of the ‘send’ method that is available on all objects. @obj = MyClass.new result =...
Auto update Gemfile when installing ruby gems
npm lets you save a module into your package.json file using the –save options. You can do the same in ruby, by installing a gem called ‘gemrat’ and then using that command to install...
How to generate a test file for an existing rails model
If you forgot to create a test file for your model, use this simple command to generate the empty scaffolding file for your Model’s unit test. rails g test_unit:model <modelname>
How to check all the rake tasks that are available for use
The rails rake command comes with a number of tasks. This tiny command shows you a list of all the rake tasks available and a short description. rake –tasks Reference http://stackoverflow.com/questions/10301794/difference-between-rake-dbmigrate-dbreset-and-dbschemaload
ruby on rails – Could not find gem ‘mysql2’
I got the above issue when I tried to create a new project with rails and asked it to use mysql instead of the default sqlite database. Apparently, I didnt have mysql installed on...
Recent Comments