This post shows how to make sitemap.xml for your web site. The sitemap will be accessible by URL http://mysite.com/sitemap.xml
Myrails::Application.routes.draw do
# (v.respond_to?(:empty?) ? v.empty? : !v) is basically rails' .blank? in plain ruby | |
class Hash | |
def delete_blank | |
delete_if do |k, v| | |
(v.respond_to?(:empty?) ? v.empty? : !v) or v.instance_of?(Hash) && v.delete_blank.empty? | |
end | |
end | |
end |
def select_from_chosen(item_text, options) | |
field = find_field(options[:from]) | |
option_value = page.evaluate_script("$(\"##{field[:id]} option:contains('#{item_text}')\").val()") | |
page.execute_script("$('##{field[:id]}').val('#{option_value}')") | |
end |
# .rubocop.yml | |
# rubocop config files for Ruby 3.0 / Rails 6+ project | |
AllCops: | |
TargetRubyVersion: 3.0 | |
NewCops: enable | |
SuggestExtensions: false | |
Include: |
This post shows how to make sitemap.xml for your web site. The sitemap will be accessible by URL http://mysite.com/sitemap.xml
Myrails::Application.routes.draw do
This is an example of how to configure nginx to allow ActionCable WebSocket connections to use the same host as your primary site. For example, instead of cable.myapp.dev
, you can use myapp.dev/_c/
.
In my case, we have a multi-tenanted environment, e.g., bob.myapp.dev
and jim.myapp.dev
. This lets the ActionCable connection still use the Host:
header to select a tenant, and use normal cookies for user identification. wss://bob.myapp.dev/_c/
is authorized as normal. It also piggybacks off of whatever TLS setup is available.
# config/enviroments/development.rb | |
config.action_mailer.preview_path = "#{Rails.root}/app/mailer_previews" | |
# app/mailer_previews/devise_mailer_preview.rb | |
class Devise::MailerPreview < ActionMailer::Preview | |
def confirmation_instructions | |
Devise::Mailer.confirmation_instructions(User.first, {}) | |
end |
Hi there! Since this post was originally written, nvm
has gained some new tools, and some people have suggested alternative (and potentially better) approaches for modern systems. Make sure to have a look at the comments to this article, before following this guide!
Trickier than it seems.
class InitialMigration < ActiveRecord::Migration[5.0] | |
def change | |
enable_extension "pgcrypto" unless extension_enabled?("pgcrypto") | |
end | |
end |
Generally, you will add a git remote for your Heroku app during the Heroku app creation process, i.e. heroku create
. However, if you are working on an existing app and want to add git remotes to enable manual deploys, the following commands may be useful.
Note that on Heroku, you must always use master
as the destination branch on the remote. If you want to deploy a different branch, you can use the syntax local_branch:destination_branch
seen below (in this example, we push the local staging
branch to the master
branch on heroku.
$ git remote add staging https://git.heroku.com/staging-app.git
If you get error like this:
Running via Spring preloader in process 7662
/Users/zulh/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require': dlopen(/Users/zulh/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
Referenced from: /Users/zulh/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
Reason: image not found - /Users/zulh/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
from /Users/zulh/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/zulh/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/zulh/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'