end
def resource_params
- params.require(:invite).permit(:max_uses, :expires_in, :autofollow)
+ params.require(:invite).permit(:max_uses, :expires_in, :autofollow, :comment)
end
def set_body_classes
# created_at :datetime not null
# updated_at :datetime not null
# autofollow :boolean default(FALSE), not null
+# comment :text
#
class Invite < ApplicationRecord
scope :available, -> { where(expires_at: nil).or(where('expires_at >= ?', Time.now.utc)) }
+ validates :comment, length: { maximum: 420 }
+
before_validation :set_code
def valid_for_use?
.fields-group
= f.input :autofollow, wrapper: :with_label
+ .fields-group
+ = f.input :comment, wrapper: :with_label, input_html: { maxlength: 420 }
+
.actions
= f.button :button, t('invites.generate'), type: :submit
%td{ colspan: 2 }
= t('invites.expired')
+ %td
+ = invite.comment
+
%td
- if invite.valid_for_use? && policy(invite).destroy?
= table_link_to 'times', t('invites.delete'), invite_path(invite), method: :delete
%th
%th= t('invites.table.uses')
%th= t('invites.table.expires_at')
+ %th= t('invites.table.comment')
%th
%tbody
= render @invites
--- /dev/null
+class AddCommentToInvites < ActiveRecord::Migration[5.2]
+ def change
+ add_column :invites, :comment, :text
+ end
+end
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "autofollow", default: false, null: false
+ t.text "comment"
t.index ["code"], name: "index_invites_on_code", unique: true
t.index ["user_id"], name: "index_invites_on_user_id"
end