forked from eagerworks/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from eagerworks/payment_method_crud
Payment method crud
- Loading branch information
Showing
13 changed files
with
221 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class PaymentMethodsController < ApplicationController | ||
def index | ||
@payment_methods = PaymentMethod.where(user: current_user) | ||
end | ||
|
||
def new | ||
@payment_method = PaymentMethod.new | ||
end | ||
|
||
def show | ||
@payment_method = PaymentMethod.find(params[:id]) | ||
end | ||
|
||
def create | ||
@payment_method = PaymentMethod.new(payment_method_params) | ||
@payment_method.user = current_user | ||
if @payment_method.save | ||
redirect_to payment_methods_path | ||
else | ||
render 'new', status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def edit | ||
@payment_method = PaymentMethod.find(params[:id]) | ||
end | ||
|
||
def update | ||
@payment_method = PaymentMethod.find(params[:id]) | ||
if @payment_method.update(payment_method_params) | ||
redirect_to payment_methods_path | ||
else | ||
render 'edit', status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@payment_method = PaymentMethod.find(params[:id]) | ||
@payment_method.destroy | ||
redirect_to payment_methods_path | ||
end | ||
|
||
private | ||
|
||
def payment_method_params | ||
params.require(:payment_method).permit(:name, :owner, :card_number, :due_date, :CVV) | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class PaymentMethod < ApplicationRecord | ||
belongs_to :user | ||
has_many :purchases | ||
|
||
validates :name, :owner, :card_number, :due_date, :CVV, presence: true | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<%= form_with model: payment_method do |form| %> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.label :name, 'Nombre', class:'fs-2 fw-light' %> | ||
<%= form.text_field :name, disabled: disable, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4', placeholder: 'Nombre' %> | ||
<% payment_method.errors.full_messages_for(:name).each do |message| %> | ||
<p class= "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.label :owner, 'Propietario', class:'fs-2 fw-light' %> | ||
<%= form.text_field :owner, disabled: disable, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4' %> | ||
<% payment_method.errors.full_messages_for(:owner).each do |message| %> | ||
<p class= "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.label :card_number, 'Número de tarjeta', class:'fs-2 fw-light' %> | ||
<%= form.text_field :card_number, disabled: disable, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4' %> | ||
<% payment_method.errors.full_messages_for(:card_number).each do |message| %> | ||
<p class= "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.label :due_date, 'Fecha de expiración', class:'fs-2 fw-light' %> | ||
<%= form.date_field :due_date, disabled: disable, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4' %> | ||
<% payment_method.errors.full_messages_for(:due_date).each do |message| %> | ||
<p class= "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.label :CVV, 'CVV', class:'fs-2 fw-light' %> | ||
<%= form.text_field :CVV, disabled: disable, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4' %> | ||
<% payment_method.errors.full_messages_for(:CVV).each do |message| %> | ||
<p class = "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class=" <%= disable ? 'd-none' : 'actions' %>"> | ||
<%= form.submit 'Actualizar', class: 'color-white bg-Blue-lg-30deg border-1 rounded-2 hover-bg-white fs-3 fs-lg-4 fs-md-6 hover-border-solid fs-xl-4 hover-border-color-mixBlue border-color-transparent w-100' %> | ||
</div> | ||
<% end %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<% content_for :header do %> | ||
<% render 'header', show_mobile: true, categories: @categories, filters: @filter, selected_tab: :none %> | ||
<% end %> | ||
<div class="px-md-6 py-md-6 d-flex justify-content-between align-items-baseline"> | ||
<div class="d-flex flex-column w-lg-50"> | ||
<h1 class= "bg-text-gradient-blue-20 text-fill-color-transparent mb-5">Información</h1> | ||
<%= render 'data_payment', payment_method: @payment_method, disable: false%> | ||
<div class="d-flex d-md-none mt-5"> | ||
<%= link_to 'Volver', payment_method_path(@payment_method), class: 'fw-light text-blue-2 text-decoration-none mb-0' %> | ||
</div> | ||
</div> | ||
<div class="d-none d-md-flex fs-md-5 fs-lg-3 "> | ||
<%= link_to 'Volver', payment_method_path(@payment_method), class: 'fw-light text-blue-2 text-decoration-none mb-0' %> | ||
</div> | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<% content_for :header do %> | ||
<% render 'header', show_mobile: true, categories: @categories, filters: @filter, selected_tab: :none %> | ||
<% end %> | ||
<div class="d-flex justify-content-between align-items-baseline"> | ||
<div class="d-flex flex-column"> | ||
<h1 class= "bg-text-gradient-blue-20 text-fill-color-transparent">Mis métodos de pago</h1> | ||
<ul class='mb-8'> | ||
<% @payment_methods.each do |payment_method| %> | ||
<li> | ||
<%= link_to payment_method.name, payment_method_path(payment_method), class: 'fw-light text-blue-2 text-decoration-none mb-0' %> - <%= payment_method.owner %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<div class="d-flex flex-column d-md-none"> | ||
<%= link_to 'Agregar nuevo método de pago', new_payment_method_path, class: 'fw-light text-blue-2 text-decoration-none mb-3' %> | ||
<%= link_to 'Volver', users_show_path, class: 'fw-light text-blue-2 text-decoration-none mb-0' %> | ||
</div> | ||
</div> | ||
<div class=""> | ||
<div class="d-none d-md-flex flex-column align-items-end fs-md-5 fs-lg-3"> | ||
<%= link_to 'Agregar nuevo método de pago', new_payment_method_path, class: 'fw-light text-blue-2 text-decoration-none mb-1' %> | ||
<%= link_to 'Volver', users_show_path, class: 'fw-light text-blue-2 text-decoration-none mb-0' %> | ||
</div> | ||
</div> | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<% content_for :header do %> | ||
<% render 'header', show_mobile: true, categories: @categories, filters: @filter, selected_tab: :none %> | ||
<% end %> | ||
<div class="px-md-6 py-md-6 d-flex justify-content-between align-items-baseline"> | ||
<div class="d-flex flex-column w-lg-50"> | ||
<h1 class= "bg-text-gradient-blue-20 text-fill-color-transparent mb-5">Nuevo método de pago</h1> | ||
<%= form_with model: @payment_method do |form| %> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.text_field :name, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4', placeholder: 'Nombre' %> | ||
<% @payment_method.errors.full_messages_for(:name).each do |message| %> | ||
<p class= "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.text_field :owner, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4', placeholder: 'Propietario' %> | ||
<% @payment_method.errors.full_messages_for(:owner).each do |message| %> | ||
<p class= "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.text_field :card_number, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4', placeholder: 'Número de tarjeta' %> | ||
<% @payment_method.errors.full_messages_for(:card_number).each do |message| %> | ||
<p class= "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.date_field :due_date, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4', placeholder: 'Fecha de expiración' %> | ||
<% @payment_method.errors.full_messages_for(:due_date).each do |message| %> | ||
<p class= "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="field mb-lg-5 mb-6 mb-md-8"> | ||
<%= form.text_field :CVV, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-md-6 fs-lg-4', placeholder: 'CVV' %> | ||
<% @payment_method.errors.full_messages_for(:CVV).each do |message| %> | ||
<p class = "text-danger"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="actions"> | ||
<%= form.submit 'Agregar', class: 'color-white bg-Blue-lg-30deg border-1 rounded-2 hover-bg-white fs-3 fs-lg-4 fs-md-6 hover-border-solid fs-xl-4 hover-border-color-mixBlue border-color-transparent w-100' %> | ||
</div> | ||
<% end %> | ||
<div class="d-flex d-md-none mt-5"> | ||
<%= link_to 'Volver', payment_methods_path, class: 'fw-light text-blue-2 text-decoration-none mb-0' %> | ||
</div> | ||
</div> | ||
<div class="d-none d-md-flex"> | ||
<%= link_to 'Volver', payment_methods_path, class: 'fw-light text-blue-2 text-decoration-none mb-0' %> | ||
</div> | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<% content_for :header do %> | ||
<% render 'header', show_mobile: true, categories: @categories, filters: @filter, selected_tab: :none %> | ||
<% end %> | ||
<div class="px-md-6 py-md-6 d-flex justify-content-between align-items-baseline"> | ||
<div class="d-flex flex-column w-lg-50"> | ||
<h1 class= "bg-text-gradient-blue-20 text-fill-color-transparent mb-5">Información</h1> | ||
<%= render 'data_payment', payment_method: @payment_method, disable: true%> | ||
<div class="d-flex flex-column d-md-none mt-5"> | ||
<%= link_to 'Editar', edit_payment_method_path(@payment_method), class: 'fw-light text-blue-2 text-decoration-none mb-2' %> | ||
<%= button_to 'Eliminar', payment_method_path(@payment_method), data: { confirm: "¿estás seguro?", turbo_confirm: "¿estás seguro?" }, method: :delete, class: 'fw-light text-blue-2 text-decoration-none mb-2 bg-transparent border-0 p-0' %> | ||
<%= link_to 'Volver', payment_methods_path, class: 'fw-light text-blue-2 text-decoration-none mb-0' %> | ||
</div> | ||
</div> | ||
<div class="d-none d-md-flex flex-column fs-md-5 fs-lg-3"> | ||
<%= link_to 'Editar', edit_payment_method_path(@payment_method), class: 'fw-light text-blue-2 text-decoration-none mb-2' %> | ||
<%= button_to 'Eliminar', payment_method_path(@payment_method), data: { confirm: "¿estás seguro?", turbo_confirm: "¿estás seguro?" }, method: :delete, class: 'fw-light text-blue-2 text-decoration-none mb-2 bg-transparent border-0 p-0' %> | ||
<%= link_to 'Volver', payment_methods_path, class: 'fw-light text-blue-2 text-decoration-none mb-0' %> | ||
</div> | ||
</div> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class PaymentMethodsControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |