What is the difference between Rails.cache.clear and rake tmp:cache:clear?

The rake task only clears out files that are stored on the filesystem in “#{Rails.root}/tmp/cache”. Here’s the code for that task. namespace :cache do # desc “Clears all files and directories in tmp/cache” task :clear do FileUtils.rm_rf(Dir[‘tmp/cache/[^.]*’]) end end https://github.com/rails/rails/blob/ef5d85709d346e55827e88f53430a2cbe1e5fb9e/railties/lib/rails/tasks/tmp.rake#L25-L30 Rails.cache.clear will do different things depending on your apps setting for config.cache_store. http://guides.rubyonrails.org/caching_with_rails.html#cache-stores If you … Read more

rails generate model

The code is okay but you are in the wrong directory. You must run these commands inside your rails project-directory. The normal way to get there from scratch is: $ rails new PROJECT_NAME $ cd PROJECT_NAME $ rails generate model ad \ name:string \ description:text \ price:decimal \ seller_id:integer \ email:string img_url:string

Rails: How to set a background image in rails from css?

In your CSS: background-image: url(background.jpg); or background-image: url(/assets/background.jpg); In environments/production.rb: # Disable Rails’s static asset server (Apache or nginx will already do this) config.serve_static_assets = false # Compress JavaScripts and CSS config.assets.compress = true # Don’t fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false # Generate digests for assets URLs … Read more

Reserved names with ActiveRecord models

Reserved Word List ADDITIONAL_LOAD_PATHS ARGF ARGV ActionController ActionView ActiveRecord ArgumentError Array BasicSocket Benchmark Bignum Binding CGI CGIMethods CROSS_COMPILING Class ClassInheritableAttributes Comparable ConditionVariable Config Continuation DRb DRbIdConv DRbObject DRbUndumped Data Date DateTime Delegater Delegator Digest Dir ENV EOFError ERB Enumerable Errno Exception FALSE FalseClass Fcntl File FileList FileTask FileTest FileUtils Fixnum Float FloatDomainError GC Gem GetoptLong … Read more

Difference between Render and Render Partial and Yield

render & render partial: render ‘some_view’ is a shorthand for render partial: ‘some_view’. render file: ‘view’ will look for a file view.html.erb and NOT _view.html.erb (.erb or any other renderer you use) render can pass local variables for the partial if you do not use collections or layouts, like render ‘some/path/to/my/partial’, custom_var: ‘Hello’ Passing local … Read more

How can i remove a column from table using rails console

You can run the code in the up method directly in rails console: >> ActiveRecord::Migration.remove_column :table_name, :column_name If you already have a migration file such as “db/migrate/20130418125100_remove_foo.rb“, you can do this: >> require “db/migrate/20130418125100_remove_foo.rb” >> RemoveFoo.up If you just want to do rake db:migrate, try this: >> ActiveRecord::Migrator.migrate “db/migrate”