Sha256: 447a745318391be70bed24944b868191bfabc107d299a59ea1142e884c6ebcdc

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

Trestle.resource(:account, model: <%= model %>, scope: Auth, singular: true) do
  instance do
    current_user
  end

  remove_action :new, :edit, :destroy

  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.encrypted_password_previously_changed?
      login!(instance)
    end
  end if Devise.sign_in_after_reset_password
  <%- end -%>

  # Limit the parameters that are permitted to be updated by the user
  params do |params|
    params.require(:account).permit(:email, <% unless devise? %>:first_name, :last_name, <% end %>:password, :password_confirmation)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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