Posts

Showing posts with the label rails

#21. Rails scope

Author has_many books books belongs_to author Named Scope scope :available, -> { where(available: true) } select 'books'.* from books where books.available = 't' scope :unavailable, -> { where(available: [nil, false]) } select 'books'.* from books where books.available = 'f' or books.available is null scope :public_status, -> { where(status:  'public') } 3.1.2 :004 > Article.public_status   Article Load (0.2ms)  SELECT "articles".* FROM "articles" WHERE "articles"."status" = ? AND "articles"."status" = ?  [["status", "public"], ["status", "public"]] Here two times same status(‘public’) checked because one of the default scope and one of the named scope( public_status ). Author.joins(:books).merge(Book.available) select authors.* from authors inner join books on books.author_id=authors.id where books.available = 't' We can achi...

#14. Rails notes command

 raj@linux:~/workspace/test_app$ rails notes -h Usage:   rails notes [options] Options:   -a, [--annotations=one two three]  # Filter by specific annotations, e.g. Foobar TODO Example, raj@linux:~/workspace/test_app$ rails notes -a DEBUG app/controllers/configs_controller.rb:   * [6] This is not exactly working raj@linux:~/workspace/test_app$ rails notes -a DEBUG TEST TODO app/controllers/application_controller.rb:   * [5] [TODO] Check this method for optimization app/controllers/configs_controller.rb:   * [6] [DEBUG] This is not exactly working app/controllers/feedbacks_controller.rb:   * [2] [TEST] Have to write test cases for this method raj@linux:~/workspace/test_app$ rails notes app/controllers/application_controller.rb:   * [5] [TODO] Check this method for optimization

#11. Run rails app in production mode

Check in produciton.rb, it should be false, config.assets.compile = false  precompile the assets, RAILS_ENV=production bundle exec rake assets:precompile It should be set in the env file as true config.public_file_server.enabled = true Then run server as, rails s -e production or RAILS_ENV=production rails s