-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add countries to admin ui. closes #52
- Loading branch information
Adam Cooke
committed
Oct 31, 2013
1 parent
8b53ab8
commit 0871802
Showing
8 changed files
with
116 additions
and
0 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,47 @@ | ||
module Shoppe | ||
class CountriesController < Shoppe::ApplicationController | ||
|
||
before_filter { @active_nav = :countries } | ||
before_filter { params[:id] && @country = Shoppe::Country.find(params[:id]) } | ||
|
||
def index | ||
@countries = Shoppe::Country.ordered | ||
end | ||
|
||
def new | ||
@country = Shoppe::Country.new | ||
end | ||
|
||
def create | ||
@country = Shoppe::Country.new(safe_params) | ||
if @country.save | ||
redirect_to :countries, :flash => {:notice => "Country has been created successfully"} | ||
else | ||
render :action => "new" | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if @country.update(safe_params) | ||
redirect_to [:edit, @country], :flash => {:notice => "Country has been updated successfully"} | ||
else | ||
render :action => "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
@country.destroy | ||
redirect_to :countries, :flash => {:notice => "Country has been removed successfully"} | ||
end | ||
|
||
private | ||
|
||
def safe_params | ||
params[:country].permit(:name, :code2, :code3, :continent, :tld, :currency, :eu_member) | ||
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
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,31 @@ | ||
= form_for @country do |f| | ||
= f.error_messages | ||
= field_set_tag "User Details" do | ||
.splitContainer | ||
%dl.third | ||
%dt= f.label :name | ||
%dd= f.text_field :name, :class => 'focus text' | ||
%dl.third | ||
%dt= f.label :code2, "ISO 3166-alpha-2" | ||
%dd= f.text_field :code2, :class => 'text' | ||
%dl.third | ||
%dt= f.label :code3, "ISO 3166-alpha-3" | ||
%dd= f.text_field :code3, :class => 'text' | ||
.splitContainer | ||
%dl.third | ||
%dt= f.label :continent | ||
%dd= f.text_field :continent, :class => 'text' | ||
%dl.third | ||
%dt= f.label :tld, "TLD" | ||
%dd= f.text_field :tld, :class => 'text' | ||
%dl.third | ||
%dt= f.label :eu_member, "EU Member?" | ||
%dd.checkbox | ||
= f.check_box :eu_member | ||
= f.label :eu_member, 'Country is an EU member?' | ||
|
||
%p.submit | ||
- unless @country.new_record? | ||
%span.right= link_to "Delete", @country, :class => 'button purple', :method => :delete, :data => {:confirm => "Are you sure you wish to remove this country?"} | ||
= f.submit :class => 'button green' | ||
= link_to "Cancel", :countries, :class => 'button' |
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 @@ | ||
- @page_title = "Countries" | ||
= content_for :header do | ||
%p.buttons= link_to "Back to countries", :countries, :class => 'button' | ||
%h2.countries Countries | ||
= render '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,25 @@ | ||
- @page_title = "Countries" | ||
|
||
= content_for :header do | ||
%p.buttons=link_to "New country", :new_country, :class => 'button green' | ||
%h2.countries Countries | ||
|
||
.table | ||
%table.data | ||
%thead | ||
%tr | ||
%th Name | ||
%th ISO 3166-1-alpha-2 | ||
%th ISO 3166-1-alpha-3 | ||
%th Continent | ||
%th TLD | ||
%th EU? | ||
%tbody | ||
- for country in @countries | ||
%tr | ||
%td= link_to country.name, [:edit, country] | ||
%td= country.code2 | ||
%td= country.code3 | ||
%td= country.continent | ||
%td= country.tld | ||
%td= boolean_tag country.eu_member? |
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 @@ | ||
- @page_title = "Countries" | ||
= content_for :header do | ||
%p.buttons= link_to "Back to countries", :countries, :class => 'button' | ||
%h2.countries Countries | ||
= render '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