Sha256: c6b5c28311e15021f6730d82e658b409f6e93fa93d1cb4520ffee61802d8b48d

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

Trestle.resource(:<%= plural_name %>, model: <%= model %>, scope: Auth) do
  menu do
    group :configuration, priority: :last do
      item :<%= plural_name %>, icon: "fas fa-users"
    end
  end

  table do
    column :avatar, header: false do |<%= parameter_name %>|
      avatar_for(<%= parameter_name %>)
    end
    column :email, link: true
    <%- unless devise? -%>
    column :first_name
    column :last_name
    <%- end -%>
    actions do |a|
      a.delete unless a.instance == current_user
    end
  end

  form do |<%= parameter_name %>|
    text_field :email

    <%- unless devise? -%>
    row do
      col(sm: 6) { text_field :first_name }
      col(sm: 6) { text_field :last_name }
    end

    <%- end -%>
    row do
      col(sm: 6) { password_field :password }
      col(sm: 6) { password_field :password_confirmation }
    end
  end
  <%- if devise? -%>

  # Ignore the password parameters if they are blank
  update_instance do |instance, attrs|
    if attrs[:password].blank?
      attrs.delete(:password)
      attrs.delete(:password_confirmation) if attrs[:password_confirmation].blank?
    end

    instance.assign_attributes(attrs)
  end

  # Log the current user back in if their password was changed
  after_action on: :update do
    if instance == current_user && instance.encrypted_password_previously_changed?
      login!(instance)
    end
  end if Devise.sign_in_after_reset_password
  <%- end -%>
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
trestle-auth-0.5.0 lib/generators/trestle/auth/admin/templates/admin.rb.erb
trestle-auth-0.5.0.pre2 lib/generators/trestle/auth/admin/templates/admin.rb.erb
trestle-auth-0.5.0.pre lib/generators/trestle/auth/admin/templates/admin.rb.erb
trestle-auth-0.4.4 lib/generators/trestle/auth/admin/templates/admin.rb.erb
trestle-auth-0.4.3 lib/generators/trestle/auth/admin/templates/admin.rb.erb
trestle-auth-0.4.2 lib/generators/trestle/auth/admin/templates/admin.rb.erb
trestle-auth-0.4.1 lib/generators/trestle/auth/admin/templates/admin.rb.erb