Skip to content

Instantly share code, notes, and snippets.

View kitsuneyo's full-sized avatar

Neil Wheatley kitsuneyo

View GitHub Profile
# 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'
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)
# 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
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
class UserPolicy < ApplicationPolicy
attr_reader :user, :other_user
def initialize(user, other_user)
@user = user
@other_user = other_user
end
def index?
user.admin?
{
"address_components": [
{
"long_name": "Paris",
"short_name": "Paris",
"types": [
"locality",
"political"
]
},
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
@kitsuneyo
kitsuneyo / locations_controller.rb
Last active November 17, 2015 10:24
location tree routing
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"
<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() {
/**/_xdc_._d0qdkm && _xdc_._d0qdkm( {
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Auckland",
"short_name" : "Auckland",
"types" : [ "locality", "political" ]
},
{