Skip to content

Commit

Permalink
add guests data
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagodiaz committed Dec 9, 2024
1 parent ea79a88 commit 555e51a
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ source "https://rubygems.org"
# ruby version
ruby "3.3.1"

gem 'rack-cors', '~> 2.0'

Check failure on line 6 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check failure on line 6 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.2.2"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
Expand Down Expand Up @@ -44,6 +46,9 @@ group :development, :test do
# Static analysis for security vulnerabilities [https://brakemanscanner.org/]
gem "brakeman", require: false

gem 'pry-byebug', '~> 3.9', platform: :mri

Check failure on line 49 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check failure on line 49 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
gem 'pry-rails', '~> 0.3.11'

Check failure on line 50 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check failure on line 50 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
gem "rubocop-rails-omakase", require: false
end
Expand Down
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ GEM
brakeman (6.2.2)
racc
builder (3.3.0)
byebug (11.1.3)
capybara (3.40.0)
addressable
matrix
Expand All @@ -93,6 +94,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
Expand Down Expand Up @@ -130,6 +132,7 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.2)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.25.2)
msgpack (1.7.5)
Expand Down Expand Up @@ -160,13 +163,23 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.9)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
pry-rails (0.3.11)
pry (>= 0.13.0)
psych (5.2.0)
stringio
public_suffix (6.0.1)
puma (6.5.0)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.8)
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down Expand Up @@ -295,7 +308,10 @@ DEPENDENCIES
importmap-rails
jbuilder
pg (~> 1.4)
pry-byebug (~> 3.9)
pry-rails (~> 0.3.11)
puma (>= 5.0)
rack-cors (~> 2.0)
rails (~> 7.2.2)
rubocop-rails-omakase
selenium-webdriver
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern

protect_from_forgery with: :null_session
end
34 changes: 26 additions & 8 deletions app/controllers/guests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,32 @@ def index
end

def create
@guest = Guest.new(guest_params)
name = params['fullName']

Check failure on line 6 in app/controllers/guests_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
phone = params['phone']

Check failure on line 7 in app/controllers/guests_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
attending = params['assist']

Check failure on line 8 in app/controllers/guests_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
partner = params['partner']

Check failure on line 9 in app/controllers/guests_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
partners_name = params['partnersName']
children_attending = params['childrens']
children_quantity = params['childrensQuantity']
assist_church = params['assistChurch']
dietary_restrictions = params['dietaryRestrictions']
dietary_restrictions_indications = params['dietaryRestrictionsIndications']
other_food_preference = params['otherFoodPreference']
message = params['message']
@guest = Guest.new(
name: name,
phone: phone,
attending: attending,
partner: partner,
partners_name: partners_name,
children_attending: children_attending,
children_quantity: children_quantity,
assist_church: assist_church,
dietary_restrictions: dietary_restrictions,
dietary_restrictions_indications: dietary_restrictions_indications,
other_food_preference: other_food_preference,
message: message
)

if @guest.save
# Puedes agregar un mensaje de éxito aquí, si lo deseas
Expand All @@ -15,11 +40,4 @@ def create
render :index
end
end

private

# Permitir solo los parámetros permitidos para crear un invitado
def guest_params
params.require(:guest).permit(:name, :email, :attending)
end
end
12 changes: 12 additions & 0 deletions config/initializers/rack_cors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# config/initializers/rack_cors.rb
# frozen_string_literal: true

Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*' # Change this to your frontend's URL in production
resource '*',
headers: :any,
methods: %i[get post options put delete],
expose: %w[access-token uid client]
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@

# Defines the root path route ("/")
# root "posts#index"
match '*path', via: :options, to: ->(env) { [204, { 'Content-Type' => 'text/plain' }, []] }
end
14 changes: 14 additions & 0 deletions db/migrate/20241209201953_add_data_to_guests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class AddDataToGuests < ActiveRecord::Migration[7.2]
def change
add_column :guests, :phone, :string
add_column :guests, :partner, :boolean, default: false, null: false
add_column :guests, :partners_name, :string, array: true, default: [], null: false # For PostgreSQL only
add_column :guests, :children_attending, :boolean, default: false, null: false
add_column :guests, :children_quantity, :integer, default: 0, null: false
add_column :guests, :assist_church, :boolean, default: false, null: false
add_column :guests, :dietary_restrictions, :boolean, default: false, null: false
add_column :guests, :dietary_restrictions_indications, :string
add_column :guests, :other_food_preference, :string
add_column :guests, :message, :text
end
end
12 changes: 11 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 555e51a

Please sign in to comment.