Snippets Collections
When you want an optional belongs_to:


1) Just don't add in the field's migration
#migration_file_name.rb
#PLEASE DO NOT DO
null: false 

2) In the model use
#PLEASE DO
belongs_to :community, optional: true
namespace :javascript do
  desc "Compiles each js file"
  task validate: :environment do
    JS_PATH = "app/assets/javascripts/**/*.js"
    Dir[JS_PATH].each do |file_name|
      puts "\n#{file_name}"
      puts Uglifier.compile(File.read(file_name))
    end
  end
end
file = "#{Rails.root}/public/users.csv"
headers = ["Name", "Company Name", "Email", "Role", "Team Name"]
CSV.open(file, 'w', write_headers: true, headers: headers) do |writer|
    Team.all.each do |team|
      team.users.each do |user|
        writer << [user.name, user.company_name , user.email, user.roles&.first&.name, team.name]
      end
    end
  end
# get "/articles?page=2"
request.original_url # => "http://www.example.com/articles?page=2"
bookmark
dashboard

Thu Aug 20 2020 01:16:40 GMT+0000 (UTC) https://stackoverflow.com/questions/46053658/how-to-make-a-models-column-optional-in-rails5

#rb #rubyonrails
bookmark
dashboard

Thu Aug 13 2020 18:18:29 GMT+0000 (UTC) https://medium.com/forest-admin/rails-migrations-tricks-guide-code-cheatsheet-included-dca935354f22

#rubyonrails #ruby
bookmark
dashboard

Thu Aug 13 2020 18:17:17 GMT+0000 (UTC) https://medium.com/forest-admin/rails-migrations-tricks-guide-code-cheatsheet-included-dca935354f22

#rubyonrails #ruby
bookmark
dashboard

Mon May 18 2020 19:08:51 GMT+0000 (UTC) https://stackoverflow.com/questions/37512603/rails-attach-some-data-to-head-ok-response

#ruby #rubyonrails
bookmark
dashboard

Mon May 11 2020 16:41:09 GMT+0000 (UTC)

#ruby #rubyonrails
bookmark
dashboard

Mon May 11 2020 16:38:22 GMT+0000 (UTC) custom

#ruby #rubyonrails
bookmark
dashboard

Tue Dec 31 2019 19:00:00 GMT+0000 (UTC) https://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url

#howto #rubyonrails #webdev #interviewquestions

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension