This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= form_for @site, url: site_pass_path(@site.name), method: :patch do |f| %> | |
| <%= f.label :password %> | |
| <%= f.password_field :password %> | |
| <%= f.submit "Add password" %> | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Site < ApplicationRecord | |
| before_save { self.name = name.downcase } | |
| before_create :lock_init | |
| VALID_NAME_REGEX = /\A[a-zA-Z\d\-]+\z/i # letters, numbers, dashes | |
| validates :name, presence: true, uniqueness: true, length: { maximum: 50 }, format: { with: VALID_NAME_REGEX } | |
| has_secure_password validations: false | |
| private | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SitesController < ApplicationController | |
| before_action :find_site, only: [:show, :add_password, :remove_password] | |
| before_action :unlocked?, only: [:add_password, :remove_password] | |
| before_action :have_posts?, only: [:add_password] | |
| def show | |
| ... | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Site < ApplicationRecord | |
| before_create :lock_init | |
| VALID_NAME_REGEX = /\A[a-zA-Z\d\-]+\z/i # letters, numbers, dashes | |
| validates :name, presence: true, uniqueness: true, length: { maximum: 50 }, format: { with: VALID_NAME_REGEX } | |
| has_secure_password validations: false | |
| private | |
| def lock_init | |
| self.locked = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SitesController < ApplicationController | |
| before_action :find_site, only: [:show] | |
| def show | |
| if @site.nil? | |
| @site = Site.new(name: @slug) | |
| if @site.save | |
| flash.now[:notice] = "Your site is ready. Hi #{@slug} :)" | |
| else |
NewerOlder