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
# Bootstrap Devise flash integration | |
def bootstrap_class_for(flash_type) | |
case flash_type | |
when 'success' | |
'alert-success' # Green | |
when 'error' | |
'alert-danger' # Red | |
when 'alert' | |
'alert-warning' # Yellow | |
when 'notice' |
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
def setup | |
@admin = users(:test_admin) | |
@pro = users(:test_pro) | |
@new_username = 'jonny' | |
@new_email = 'new@email.com' | |
@new_role = 'member' | |
end | |
test 'admin can edit non-admin user' do | |
log_in_as(@admin) |
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
# Store last URL so user can be redirected to it after login. | |
def store_location | |
session['user_return_to'] = request.fullpath if | |
request.fullpath != '/login' && | |
request.fullpath != '/register' && | |
request.fullpath != '/forgot-password' && | |
request.fullpath != '/logout' && | |
!request.fullpath.include?('confirmation_token=') && | |
!request.xhr? | |
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
def update | |
@user = User.find(params[:id]) | |
authorize @user | |
if @user.update(admin_user_params) | |
if account_data_changed?(@user) | |
Admin::UserMailer.account_change(@user).deliver_later | |
end | |
redirect_to admin_users_path, success: "User updated: #{@user.username}" | |
else |
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
class UserPolicy < ApplicationPolicy | |
attr_reader :user, :other_user | |
def initialize(user, other_user) | |
@user = user | |
@other_user = other_user | |
end | |
def index? | |
user.admin? |
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
{ | |
"address_components": [ | |
{ | |
"long_name": "Paris", | |
"short_name": "Paris", | |
"types": [ | |
"locality", | |
"political" | |
] | |
}, |
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
Rails.application.routes.draw do | |
mount SubdivisionSelect::Engine, at: 'subdivisions' | |
resources :locations, only: [:index, :create, :destroy] | |
get 'location/:country_slug/:state_slug/:city_slug', | |
to: 'locations#show', as: :location | |
root 'locations#index' | |
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
class LocationsController < ApplicationController | |
def index | |
@location = Location.new | |
@locations = Location.all | |
end | |
def create | |
@location = Location.new(location_params) | |
if @location.save | |
flash[:success] = "Location saved" |
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
<div id="place-form"> | |
<%= form_for(@location) do |f| %> | |
<div class="form-group"> | |
<%= f.text_field :city, class: 'form-control', id: 'places' %> | |
</div> | |
<% end %> | |
</div> | |
<script> | |
$(function() { |
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
/**/_xdc_._d0qdkm && _xdc_._d0qdkm( { | |
"html_attributions" : [], | |
"result" : { | |
"address_components" : [ | |
{ | |
"long_name" : "Auckland", | |
"short_name" : "Auckland", | |
"types" : [ "locality", "political" ] | |
}, | |
{ |
OlderNewer