country_state_select 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +126 -8
- data/app/controllers/country_state_select/cscs_controller.rb +9 -0
- data/config/routes.rb +4 -4
- data/country_state_select.gemspec +16 -10
- data/lib/country_state_select.rb +33 -22
- data/lib/country_state_select/version.rb +1 -1
- data/spec/country_state_select_spec.rb +172 -0
- data/spec/spec_helper.rb +8 -0
- data/test/dummy/Gemfile +40 -43
- data/test/dummy/app/assets/javascripts/application.js +4 -3
- data/test/dummy/app/assets/javascripts/locations.coffee +2 -0
- data/test/dummy/app/assets/stylesheets/application.scss +16 -0
- data/test/dummy/app/assets/stylesheets/{users.css.scss → locations.css.scss} +1 -1
- data/test/dummy/app/controllers/locations_controller.rb +55 -0
- data/test/dummy/app/form/location_form.rb +11 -0
- data/test/dummy/app/models/location.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +7 -5
- data/test/dummy/app/views/locations/_form.html.erb +15 -0
- data/test/dummy/app/views/locations/index.html.erb +29 -0
- data/test/dummy/app/views/locations/new.html.erb +13 -0
- data/test/dummy/app/views/locations/show.html.erb +13 -0
- data/test/dummy/bin/bundle +0 -0
- data/test/dummy/bin/rails +0 -0
- data/test/dummy/bin/rake +0 -0
- data/test/dummy/config/environments/production.rb +1 -1
- data/test/dummy/config/initializers/simple_form.rb +165 -0
- data/test/dummy/config/locales/simple_form.en.yml +31 -0
- data/test/dummy/config/routes.rb +2 -56
- data/test/dummy/db/migrate/20140724080030_create_locations.rb +10 -0
- data/test/dummy/db/migrate/20151024160724_add_test_city_to_locations.rb +5 -0
- data/test/dummy/db/schema.rb +5 -8
- data/vendor/assets/javascript/country_state_select.js.erb +159 -36
- metadata +172 -39
- data/lib/country_state_select/cst_data.rb +0 -17
- data/test/dummy/app/assets/javascripts/users.js.coffee +0 -9
- data/test/dummy/app/assets/stylesheets/application.css +0 -14
- data/test/dummy/app/assets/stylesheets/scaffolds.css.scss +0 -69
- data/test/dummy/app/controllers/users_controller.rb +0 -74
- data/test/dummy/app/helpers/users_helper.rb +0 -2
- data/test/dummy/app/models/user.rb +0 -2
- data/test/dummy/app/views/users/_form.html.erb +0 -35
- data/test/dummy/app/views/users/edit.html.erb +0 -6
- data/test/dummy/app/views/users/index.html.erb +0 -35
- data/test/dummy/app/views/users/index.json.jbuilder +0 -4
- data/test/dummy/app/views/users/new.html.erb +0 -5
- data/test/dummy/app/views/users/show.html.erb +0 -27
- data/test/dummy/app/views/users/show.json.jbuilder +0 -1
- data/test/dummy/db/migrate/20140724080030_create_users.rb +0 -12
- data/test/dummy/db/migrate/20140728194622_add_state_name_to_users.rb +0 -5
- data/test/dummy/db/migrate/20140728203606_add_country_name_to_user.rb +0 -5
- data/test/dummy/test/controllers/users_controller_test.rb +0 -49
- data/test/dummy/test/fixtures/users.yml +0 -13
- data/test/dummy/test/helpers/users_helper_test.rb +0 -4
- data/test/dummy/test/models/user_test.rb +0 -7
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
# @author Arvind Vyas
|
5
|
-
|
6
|
-
module CountryStateSelect
|
7
|
-
require 'city-state'
|
8
|
-
module CstData
|
9
|
-
def self.countries
|
10
|
-
CS.countries
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.states(country)
|
14
|
-
CS.states(country)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
$(document).on 'ready page:load', ->
|
2
|
-
$('.chosen-select').change ->
|
3
|
-
if $('#state_name option').size() > 1
|
4
|
-
$("#state_name" ).chosen() //this will add the chosen-select in to the state select
|
5
|
-
$("#state_name_chosen").empty();
|
6
|
-
$('.chosen-select').chosen
|
7
|
-
allow_single_deselect: true
|
8
|
-
no_results_text: 'No results matched'
|
9
|
-
width: '280px'
|
@@ -1,14 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
-
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
-
*
|
11
|
-
*= require_self
|
12
|
-
*= require chosen
|
13
|
-
*= require_tree .
|
14
|
-
*/
|
@@ -1,69 +0,0 @@
|
|
1
|
-
body {
|
2
|
-
background-color: #fff;
|
3
|
-
color: #333;
|
4
|
-
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
-
font-size: 13px;
|
6
|
-
line-height: 18px;
|
7
|
-
}
|
8
|
-
|
9
|
-
p, ol, ul, td {
|
10
|
-
font-family: verdana, arial, helvetica, sans-serif;
|
11
|
-
font-size: 13px;
|
12
|
-
line-height: 18px;
|
13
|
-
}
|
14
|
-
|
15
|
-
pre {
|
16
|
-
background-color: #eee;
|
17
|
-
padding: 10px;
|
18
|
-
font-size: 11px;
|
19
|
-
}
|
20
|
-
|
21
|
-
a {
|
22
|
-
color: #000;
|
23
|
-
&:visited {
|
24
|
-
color: #666;
|
25
|
-
}
|
26
|
-
&:hover {
|
27
|
-
color: #fff;
|
28
|
-
background-color: #000;
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
div {
|
33
|
-
&.field, &.actions {
|
34
|
-
margin-bottom: 10px;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
#notice {
|
39
|
-
color: green;
|
40
|
-
}
|
41
|
-
|
42
|
-
.field_with_errors {
|
43
|
-
padding: 2px;
|
44
|
-
background-color: red;
|
45
|
-
display: table;
|
46
|
-
}
|
47
|
-
|
48
|
-
#error_explanation {
|
49
|
-
width: 450px;
|
50
|
-
border: 2px solid red;
|
51
|
-
padding: 7px;
|
52
|
-
padding-bottom: 0;
|
53
|
-
margin-bottom: 20px;
|
54
|
-
background-color: #f0f0f0;
|
55
|
-
h2 {
|
56
|
-
text-align: left;
|
57
|
-
font-weight: bold;
|
58
|
-
padding: 5px 5px 5px 15px;
|
59
|
-
font-size: 12px;
|
60
|
-
margin: -7px;
|
61
|
-
margin-bottom: 0px;
|
62
|
-
background-color: #c00;
|
63
|
-
color: #fff;
|
64
|
-
}
|
65
|
-
ul li {
|
66
|
-
font-size: 12px;
|
67
|
-
list-style: square;
|
68
|
-
}
|
69
|
-
}
|
@@ -1,74 +0,0 @@
|
|
1
|
-
class UsersController < ApplicationController
|
2
|
-
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
3
|
-
|
4
|
-
# GET /users
|
5
|
-
# GET /users.json
|
6
|
-
def index
|
7
|
-
@users = User.all
|
8
|
-
end
|
9
|
-
|
10
|
-
# GET /users/1
|
11
|
-
# GET /users/1.json
|
12
|
-
def show
|
13
|
-
end
|
14
|
-
|
15
|
-
# GET /users/new
|
16
|
-
def new
|
17
|
-
@user = User.new
|
18
|
-
end
|
19
|
-
|
20
|
-
# GET /users/1/edit
|
21
|
-
def edit
|
22
|
-
end
|
23
|
-
|
24
|
-
# POST /users
|
25
|
-
# POST /users.json
|
26
|
-
def create
|
27
|
-
@user = User.new(user_params)
|
28
|
-
|
29
|
-
respond_to do |format|
|
30
|
-
if @user.save
|
31
|
-
format.html { redirect_to @user, notice: 'User was successfully created.' }
|
32
|
-
format.json { render action: 'show', status: :created, location: @user }
|
33
|
-
else
|
34
|
-
format.html { render action: 'new' }
|
35
|
-
format.json { render json: @user.errors, status: :unprocessable_entity }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# PATCH/PUT /users/1
|
41
|
-
# PATCH/PUT /users/1.json
|
42
|
-
def update
|
43
|
-
respond_to do |format|
|
44
|
-
if @user.update(user_params)
|
45
|
-
format.html { redirect_to @user, notice: 'User was successfully updated.' }
|
46
|
-
format.json { head :no_content }
|
47
|
-
else
|
48
|
-
format.html { render action: 'edit' }
|
49
|
-
format.json { render json: @user.errors, status: :unprocessable_entity }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# DELETE /users/1
|
55
|
-
# DELETE /users/1.json
|
56
|
-
def destroy
|
57
|
-
@user.destroy
|
58
|
-
respond_to do |format|
|
59
|
-
format.html { redirect_to users_url }
|
60
|
-
format.json { head :no_content }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
# Use callbacks to share common setup or constraints between actions.
|
66
|
-
def set_user
|
67
|
-
@user = User.find(params[:id])
|
68
|
-
end
|
69
|
-
|
70
|
-
# Never trust parameters from the scary internet, only allow the white list through.
|
71
|
-
def user_params
|
72
|
-
params.require(:user).permit(:name, :email, :country_id, :state_id, :state_name, :country_name)
|
73
|
-
end
|
74
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
<%= form_for(@user) do |f| %>
|
2
|
-
<% if @user.errors.any? %>
|
3
|
-
<div id="error_explanation">
|
4
|
-
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
|
5
|
-
|
6
|
-
<ul>
|
7
|
-
<% @user.errors.full_messages.each do |msg| %>
|
8
|
-
<li><%= msg %></li>
|
9
|
-
<% end %>
|
10
|
-
</ul>
|
11
|
-
</div>
|
12
|
-
<% end %>
|
13
|
-
|
14
|
-
<div class="field">
|
15
|
-
<%= f.label :name %><br>
|
16
|
-
<%= f.text_field :name %>
|
17
|
-
</div>
|
18
|
-
<div class="field">
|
19
|
-
<%= f.label :email %><br>
|
20
|
-
<%= f.text_field :email %>
|
21
|
-
</div>
|
22
|
-
<div class="field">
|
23
|
-
<%= f.label :country_id %><br>
|
24
|
-
<%= f.select :country_name, CountryStateSelect.countries.collect {|p| [ p[ 1], p[0] ] }, {}, id: 'country_id', :class=>'chosen-select' %>
|
25
|
-
|
26
|
-
</div>
|
27
|
-
<div class="field">
|
28
|
-
<%= f.label :state_name %><br>
|
29
|
-
<%= f.text_field :state_name ,:id=>'state_name', class: 'chosen-select' %>
|
30
|
-
|
31
|
-
</div>
|
32
|
-
<div class="actions">
|
33
|
-
<%= f.submit %>
|
34
|
-
</div>
|
35
|
-
<% end %>
|
@@ -1,35 +0,0 @@
|
|
1
|
-
<h1>Listing users</h1>
|
2
|
-
|
3
|
-
<table>
|
4
|
-
<thead>
|
5
|
-
<tr>
|
6
|
-
<th>Name</th>
|
7
|
-
<th>Email</th>
|
8
|
-
<th>Country</th>
|
9
|
-
<th>Country Name from second select</th>
|
10
|
-
<th>State</th>
|
11
|
-
<th></th>
|
12
|
-
<th></th>
|
13
|
-
<th></th>
|
14
|
-
</tr>
|
15
|
-
</thead>
|
16
|
-
|
17
|
-
<tbody>
|
18
|
-
<% @users.each do |user| %>
|
19
|
-
<tr>
|
20
|
-
<td><%= user.name %></td>
|
21
|
-
<td><%= user.email %></td>
|
22
|
-
<td><%#= CountryStateSelect::Constant::COUNTRIES[user.country_id] %></td>
|
23
|
-
<td><%= user.country_name%></td>
|
24
|
-
<td><%= user.state_name %></td>
|
25
|
-
<td><%= link_to 'Show', user %></td>
|
26
|
-
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
27
|
-
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
28
|
-
</tr>
|
29
|
-
<% end %>
|
30
|
-
</tbody>
|
31
|
-
</table>
|
32
|
-
|
33
|
-
<br>
|
34
|
-
|
35
|
-
<%= link_to 'New User', new_user_path %>
|
@@ -1,27 +0,0 @@
|
|
1
|
-
<p id="notice"><%= notice %></p>
|
2
|
-
|
3
|
-
<p>
|
4
|
-
<strong>Name:</strong>
|
5
|
-
<%= @user.name %>
|
6
|
-
</p>
|
7
|
-
|
8
|
-
<p>
|
9
|
-
<strong>Email:</strong>
|
10
|
-
<%= @user.email %>
|
11
|
-
</p>
|
12
|
-
|
13
|
-
<p>
|
14
|
-
<strong>Country:</strong>
|
15
|
-
<%# = CountryStateSelect::Constant::COUNTRIES[@user.country_id] %>
|
16
|
-
</p>
|
17
|
-
<p>
|
18
|
-
<strong>Country Name From second drop down:</strong>
|
19
|
-
<%= @user.country_name %>
|
20
|
-
</p>
|
21
|
-
<p>
|
22
|
-
<strong>State:</strong>
|
23
|
-
<%= @user.state_name %>
|
24
|
-
</p>
|
25
|
-
|
26
|
-
<%= link_to 'Edit', edit_user_path(@user) %> |
|
27
|
-
<%= link_to 'Back', users_path %>
|
@@ -1 +0,0 @@
|
|
1
|
-
json.extract! @user, :id, :name, :email, :country_id, :state_id, :created_at, :updated_at
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class UsersControllerTest < ActionController::TestCase
|
4
|
-
setup do
|
5
|
-
@user = users(:one)
|
6
|
-
end
|
7
|
-
|
8
|
-
test "should get index" do
|
9
|
-
get :index
|
10
|
-
assert_response :success
|
11
|
-
assert_not_nil assigns(:users)
|
12
|
-
end
|
13
|
-
|
14
|
-
test "should get new" do
|
15
|
-
get :new
|
16
|
-
assert_response :success
|
17
|
-
end
|
18
|
-
|
19
|
-
test "should create user" do
|
20
|
-
assert_difference('User.count') do
|
21
|
-
post :create, user: { country_id: @user.country_id, email: @user.email, name: @user.name, state_id: @user.state_id }
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_redirected_to user_path(assigns(:user))
|
25
|
-
end
|
26
|
-
|
27
|
-
test "should show user" do
|
28
|
-
get :show, id: @user
|
29
|
-
assert_response :success
|
30
|
-
end
|
31
|
-
|
32
|
-
test "should get edit" do
|
33
|
-
get :edit, id: @user
|
34
|
-
assert_response :success
|
35
|
-
end
|
36
|
-
|
37
|
-
test "should update user" do
|
38
|
-
patch :update, id: @user, user: { country_id: @user.country_id, email: @user.email, name: @user.name, state_id: @user.state_id }
|
39
|
-
assert_redirected_to user_path(assigns(:user))
|
40
|
-
end
|
41
|
-
|
42
|
-
test "should destroy user" do
|
43
|
-
assert_difference('User.count', -1) do
|
44
|
-
delete :destroy, id: @user
|
45
|
-
end
|
46
|
-
|
47
|
-
assert_redirected_to users_path
|
48
|
-
end
|
49
|
-
end
|