-
Notifications
You must be signed in to change notification settings - Fork 1
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 #2 from shivam091/0.2.0
0.2.0
- Loading branch information
Showing
30 changed files
with
629 additions
and
3 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
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,4 @@ | ||
c | ||
@bootstrap_form_options | ||
c | ||
@bootstrap_form_options |
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,70 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class UsersController < ApplicationController | ||
|
||
before_action :find_user, except: [:index, :new, :create] | ||
|
||
def index | ||
@users = ::User.all | ||
end | ||
|
||
def new | ||
@user = ::User.new | ||
end | ||
|
||
def create | ||
@user = ::User.new(user_params) | ||
if @user.save | ||
redirect_to users_path | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if @user.update(user_params) | ||
redirect_to users_path | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@user.destroy | ||
redirect_to users_path | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit( | ||
:name, | ||
:email, | ||
:password, | ||
:mobile_number, | ||
:birth_date, | ||
:terms, | ||
:excellence, | ||
:blog_url, | ||
:fruit_id, | ||
:favorite_color, | ||
skill_ids: [], | ||
address_attributes: [ | ||
:street, | ||
:state, | ||
:city, | ||
:postal_code, | ||
:country_id, | ||
] | ||
) | ||
end | ||
|
||
def find_user | ||
@user = ::User.find(params.fetch(:id)) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class Address < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :country | ||
|
||
delegate :name, to: :country, prefix: 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,17 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class Country < ApplicationRecord | ||
DEFAULT_OPTIONS = [ | ||
"India", | ||
"Ireland", | ||
"United States", | ||
"United Kingdom", | ||
"Spain", | ||
"France", | ||
"Canada" | ||
].freeze | ||
|
||
has_many :addresses, dependent: :restrict_with_exception | ||
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,14 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class Fruit < ApplicationRecord | ||
DEFAULT_OPTIONS = [ | ||
"Mango", | ||
"Apple", | ||
"Orange", | ||
"Watermelon" | ||
].freeze | ||
|
||
has_many :users, dependent: :restrict_with_exception | ||
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,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class Skill < ApplicationRecord | ||
DEFAULT_OPTIONS = [ | ||
"Communication", | ||
"Problem Solving", | ||
"Leadership", | ||
"Writing", | ||
"Creativity", | ||
"Time Management", | ||
"Team Work", | ||
"Negotiation", | ||
"Decision Making", | ||
"Management" | ||
].freeze | ||
|
||
has_many :user_skills, dependent: :restrict_with_exception | ||
has_many :users, through: :user_skills, source: :user | ||
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,20 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class User < ApplicationRecord | ||
has_one :address, dependent: :destroy | ||
|
||
has_many :user_skills, dependent: :destroy | ||
has_many :skills, through: :user_skills, source: :skill | ||
|
||
belongs_to :fruit | ||
|
||
delegate :name, to: :fruit, prefix: true | ||
|
||
accepts_nested_attributes_for :address, update_only: true | ||
|
||
def address | ||
super.presence || build_address | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class UserSkill < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :skill | ||
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,5 @@ | ||
<% if false %> | ||
<%= render partial: "users/form_without_bootstrap_helpers" %> | ||
<% end %> | ||
<%= render partial: "users/vertical_form" %> |
49 changes: 49 additions & 0 deletions
49
demo/app/views/users/_form_without_bootstrap_helpers.html.erb
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 @@ | ||
<div class="card card-primary my-3"> | ||
<div class="card-header fw-bold"> | ||
Profile Form (Without RailsBootstrapForm) | ||
</div> | ||
<div class="card-body"> | ||
<%= form_for @user do |form| %> | ||
<%= form.text_field :name, autocomplete: "new-name" %> | ||
<%= form.email_field :email %> | ||
<%= form.password_field :password, autocomplete: "new-password" %> | ||
<%= form.phone_field :mobile_number %> | ||
<%= form.date_field :birth_date %> | ||
<%= form.check_box :terms %> | ||
<%= form.range_field :excellence %> | ||
<%= form.url_field :blog_url %> | ||
<%= form.url_field :favorite_color %> | ||
<%= form.select :fruit_id, options_for_select(::Fruit.pluck(:name, :id), form.object.fruit_id), include_blank: "Select Favorite Fruit" %> | ||
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name do |b| %> | ||
<%= b.check_box + b.text %> | ||
<% end %> | ||
<%= form.fields_for :address, include_id: false do |address_form| %> | ||
<%= address_form.text_area :street %> | ||
<%= address_form.text_field :state %> | ||
<%= address_form.text_field :city %> | ||
<%= address_form.text_field :postal_code %> | ||
<%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id), include_blank: "Select Country" %> | ||
<% end %> | ||
<div class="mt-3"> | ||
<%= form.submit "Register", class: "btn btn-primary" %> | ||
<%= link_to "Cancel", users_path, class: "btn btn-secondary" %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
|
||
<div class="card card-primary"> | ||
<div class="card-header fw-bold"> | ||
Login Form (Without RailsBootstrapForm) | ||
</div> | ||
<div class="card-body"> | ||
<%= form_for @user do |form| %> | ||
<%= form.email_field :email %> | ||
<%= form.password_field :password, autocomplete: "new-password" %> | ||
<div class="mt-3"> | ||
<%= form.submit "Login", class: "btn btn-primary" %> | ||
<%= link_to "Cancel", users_path, class: "btn btn-secondary" %> | ||
</div> | ||
<% end %> | ||
</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,33 @@ | ||
<div class="card card-primary my-3"> | ||
<div class="card-header fw-bold"> | ||
Profile Form (Vertical layout) | ||
</div> | ||
<div class="card-body"> | ||
<%= bootstrap_form_for @user, bootstrap_form: {} do |form| %> | ||
<%= form.text_field :name, autocomplete: "new-name", required: true, bootstrap_form: {} %> | ||
<%= form.text_field :email, autocomplete: "new-email", bootstrap_form: {} %> | ||
<%= form.text_field :password, autocomplete: "new-password" %> | ||
<%= form.phone_field :mobile_number %> | ||
<%= form.date_field :birth_date %> | ||
<%= form.check_box :terms %> | ||
<%= form.range_field :excellence %> | ||
<%= form.url_field :blog_url %> | ||
<%= form.url_field :favorite_color %> | ||
<%= form.select :fruit_id, options_for_select(::Fruit.pluck(:name, :id), form.object.fruit_id), include_blank: "Select Favorite Fruit" %> | ||
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name do |b| %> | ||
<%= b.check_box + b.text %> | ||
<% end %> | ||
<%= form.fields_for :address, include_id: false do |address_form| %> | ||
<%= address_form.text_area :street %> | ||
<%= address_form.text_field :state %> | ||
<%= address_form.text_field :city %> | ||
<%= address_form.text_field :postal_code %> | ||
<%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id), {include_blank: "Select Country", bootstrap: {}} %> | ||
<% end %> | ||
<div class="mt-3"> | ||
<%= form.submit "Register", class: "btn btn-primary" %> | ||
<%= link_to "Cancel", users_path, class: "btn btn-secondary" %> | ||
</div> | ||
<% end %> | ||
</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 @@ | ||
<%= render partial: "form" %> |
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,42 @@ | ||
<div class="card card-primary"> | ||
<div class="card-header"> | ||
<div class="text-end"> | ||
<%= link_to "New user", new_user_path, class: "btn btn-primary" %> | ||
</div> | ||
</div> | ||
<div class="card-body"> | ||
<div class="table-responsive mt-3"> | ||
<table class="table table-bordered table-stripped"> | ||
<thead> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">Name</th> | ||
<th scope="col">Email</th> | ||
<th scope="col">Mobile number</th> | ||
<th scope="col">Favorite Fruit</th> | ||
<th scope="col">Country</th> | ||
<th scope="col" width="15%">Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @users.each.with_index(1) do |user, index| %> | ||
<tr style="vertical-align: middle;"> | ||
<td><%= index %></td> | ||
<td><%= user.name %></td> | ||
<td><%= user.email %></td> | ||
<td><%= user.mobile_number %></td> | ||
<td><%= user.fruit_name %></td> | ||
<td><%= user.address.country_name %></td> | ||
<td> | ||
<%= link_to "Edit", edit_user_path(user), class: "btn btn-sm btn-secondary" %> | ||
<div class="d-inline-block"> | ||
<%= button_to "Delete", user, class: "btn btn-sm btn-danger", method: :delete %> | ||
</div> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</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 @@ | ||
<%= render partial: "form" %> |
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 |
---|---|---|
|
@@ -3,4 +3,7 @@ | |
# -*- warn_indent: true -*- | ||
|
||
Rails.application.routes.draw do | ||
root to: "users#index" | ||
|
||
resources :users | ||
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,12 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class CreateCountries < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :countries do |t| | ||
t.string :name | ||
t.timestamps | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class CreateFruits < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :fruits do |t| | ||
t.string :name | ||
t.timestamps | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class CreateUsers < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :users do |t| | ||
t.string :name | ||
t.string :email | ||
t.string :password | ||
t.string :mobile_number | ||
t.string :blog_url | ||
t.date :birth_date | ||
t.references :fruit | ||
t.boolean :terms | ||
t.string :excellence | ||
t.string :favorite_color | ||
t.timestamps | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
class CreateAddresses < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :addresses, id: false do |t| | ||
t.references :user, primary_key: true | ||
t.references :country | ||
t.string :street | ||
t.string :city | ||
t.string :state | ||
t.string :postal_code | ||
t.timestamps | ||
end | ||
end | ||
end |
Oops, something went wrong.