Skip to content

Instantly share code, notes, and snippets.

@e-fu
Created December 3, 2012 17:57
Show Gist options
  • Save e-fu/4196729 to your computer and use it in GitHub Desktop.
Save e-fu/4196729 to your computer and use it in GitHub Desktop.
path in DB with Rails
= simple_form_for(@page) do |f|
= f.error_notification
.form-inputs
= f.input :name
= f.input :url
= f.input :permalink
= f.collection_select :parent_id, Page.order(:name), :id, :permalink, include_blank: true
.form-actions
= f.button :submit
migration
class CreatePages < ActiveRecord::Migration
def change
create_table :pages do |t|
t.string :name
t.string :url
t.string :permalink
t.string :ancestry
t.timestamps
end
add_index :pages, :permalink
add_index :pages, :ancestry
end
end
class PagesController < ApplicationController
# GET /pages
# GET /pages.json
def index
@pages = Page.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @pages }
end
end
# GET /pages/1
# GET /pages/1.json
def show
@page = Page.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @page }
end
end
# GET /pages/new
# GET /pages/new.json
def new
@page = Page.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @page }
end
end
# GET /pages/1/edit
def edit
@page = Page.find(params[:id])
end
# POST /pages
# POST /pages.json
def create
@page = Page.new(page_params)
respond_to do |format|
if @page.save
format.html { redirect_to @page, notice: 'Page was successfully created.' }
format.json { render json: @page, status: :created, location: @page }
else
format.html { render action: "new" }
format.json { render json: @page.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /pages/1
# PATCH/PUT /pages/1.json
def update
@page = Page.find(params[:id])
respond_to do |format|
if @page.update_attributes(page_params)
format.html { redirect_to @page, notice: 'Page was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @page.errors, status: :unprocessable_entity }
end
end
end
# DELETE /pages/1
# DELETE /pages/1.json
def destroy
@page = Page.find(params[:id])
@page.destroy
respond_to do |format|
format.html { redirect_to pages_url }
format.json { head :no_content }
end
end
private
# Use this method to whitelist the permissible parameters. Example:
# params.require(:person).permit(:name, :age)
# Also, you can specialize this method with per-user checking of permissible attributes.
def page_params
params.require(:page).permit(:ancestry, :url, :name, :permalink, :parent_id)
end
end
update_user_confirmation PUT (/:locale)/admin/user/confirmation(.:format) confirmations#update {:locale=>/en|de/}
GET (/:locale)/admin/users/auth/:provider(.:format) users/omniauth_callbacks#passthru {:locale=>/en|de/}
login GET (/:locale)/login(.:format) sessions#new {:locale=>/en|de/}
logout GET (/:locale)/logout(.:format) sessions#destroy {:locale=>/en|de/}
new_user_session GET (/:locale)/users/sign_in(.:format) sessions#new {:locale=>/en|de/}
user_session POST (/:locale)/users/sign_in(.:format) sessions#create {:locale=>/en|de/}
destroy_user_session DELETE (/:locale)/users/sign_out(.:format) sessions#destroy {:locale=>/en|de/}
user_omniauth_authorize /users/auth/:provider(.:format) omniauth_callbacks#passthru {:provider=>/facebook/, :locale=>/en|de/}
user_omniauth_callback /users/auth/:action/callback(.:format) omniauth_callbacks#(?-mix:facebook) {:locale=>/en|de/}
user_password POST (/:locale)/users/password(.:format) devise/passwords#create {:locale=>/en|de/}
new_user_password GET (/:locale)/users/password/new(.:format) devise/passwords#new {:locale=>/en|de/}
edit_user_password GET (/:locale)/users/password/edit(.:format) devise/passwords#edit {:locale=>/en|de/}
PUT (/:locale)/users/password(.:format) devise/passwords#update {:locale=>/en|de/}
cancel_user_registration GET (/:locale)/users/cancel(.:format) registrations#cancel {:locale=>/en|de/}
user_registration POST (/:locale)/users(.:format) registrations#create {:locale=>/en|de/}
new_user_registration GET (/:locale)/users/sign_up(.:format) registrations#new {:locale=>/en|de/}
edit_user_registration GET (/:locale)/users/edit(.:format) registrations#edit {:locale=>/en|de/}
PUT (/:locale)/users(.:format) registrations#update {:locale=>/en|de/}
DELETE (/:locale)/users(.:format) registrations#destroy {:locale=>/en|de/}
user_confirmation POST (/:locale)/users/confirmation(.:format) confirmations#create {:locale=>/en|de/}
new_user_confirmation GET (/:locale)/users/confirmation/new(.:format) confirmations#new {:locale=>/en|de/}
GET (/:locale)/users/confirmation(.:format) confirmations#show {:locale=>/en|de/}
user_unlock POST (/:locale)/users/unlock(.:format) devise/unlocks#create {:locale=>/en|de/}
new_user_unlock GET (/:locale)/users/unlock/new(.:format) devise/unlocks#new {:locale=>/en|de/}
GET (/:locale)/users/unlock(.:format) devise/unlocks#show {:locale=>/en|de/}
bulk_invite GET (/:locale)/admin/users/bulk_invite/:quantity(.:format) users#bulk_invite {:locale=>/en|de/}
invite_user GET (/:locale)/users/:id/invite(.:format) users#invite {:locale=>/en|de/}
users GET (/:locale)/users(.:format) users#index {:locale=>/en|de/}
POST (/:locale)/users(.:format) users#create {:locale=>/en|de/}
new_user GET (/:locale)/users/new(.:format) users#new {:locale=>/en|de/}
edit_user GET (/:locale)/users/:id/edit(.:format) users#edit {:locale=>/en|de/}
user GET (/:locale)/users/:id(.:format) users#show {:locale=>/en|de/}
PUT (/:locale)/users/:id(.:format) users#update {:locale=>/en|de/}
DELETE (/:locale)/users/:id(.:format) users#destroy {:locale=>/en|de/}
location_cabinets GET (/:locale)/locations/:location_id/cabinets(.:format) cabinets#index {:locale=>/en|de/}
POST (/:locale)/locations/:location_id/cabinets(.:format) cabinets#create {:locale=>/en|de/}
new_location_cabinet GET (/:locale)/locations/:location_id/cabinets/new(.:format) cabinets#new {:locale=>/en|de/}
edit_location_cabinet GET (/:locale)/locations/:location_id/cabinets/:id/edit(.:format) cabinets#edit {:locale=>/en|de/}
location_cabinet GET (/:locale)/locations/:location_id/cabinets/:id(.:format) cabinets#show {:locale=>/en|de/}
PUT (/:locale)/locations/:location_id/cabinets/:id(.:format) cabinets#update {:locale=>/en|de/}
DELETE (/:locale)/locations/:location_id/cabinets/:id(.:format) cabinets#destroy {:locale=>/en|de/}
locations GET (/:locale)/locations(.:format) locations#index {:locale=>/en|de/}
POST (/:locale)/locations(.:format) locations#create {:locale=>/en|de/}
new_location GET (/:locale)/locations/new(.:format) locations#new {:locale=>/en|de/}
edit_location GET (/:locale)/locations/:id/edit(.:format) locations#edit {:locale=>/en|de/}
location GET (/:locale)/locations/:id(.:format) locations#show {:locale=>/en|de/}
PUT (/:locale)/locations/:id(.:format) locations#update {:locale=>/en|de/}
DELETE (/:locale)/locations/:id(.:format) locations#destroy {:locale=>/en|de/}
GET (/:locale)/locations(.:format) locations#index {:locale=>/en|de/}
POST (/:locale)/locations(.:format) locations#create {:locale=>/en|de/}
GET (/:locale)/locations/new(.:format) locations#new {:locale=>/en|de/}
GET (/:locale)/locations/:id/edit(.:format) locations#edit {:locale=>/en|de/}
GET (/:locale)/locations/:id(.:format) locations#show {:locale=>/en|de/}
PUT (/:locale)/locations/:id(.:format) locations#update {:locale=>/en|de/}
DELETE (/:locale)/locations/:id(.:format) locations#destroy {:locale=>/en|de/}
cabinets GET (/:locale)/cabinets(.:format) cabinets#index {:locale=>/en|de/}
POST (/:locale)/cabinets(.:format) cabinets#create {:locale=>/en|de/}
new_cabinet GET (/:locale)/cabinets/new(.:format) cabinets#new {:locale=>/en|de/}
edit_cabinet GET (/:locale)/cabinets/:id/edit(.:format) cabinets#edit {:locale=>/en|de/}
cabinet GET (/:locale)/cabinets/:id(.:format) cabinets#show {:locale=>/en|de/}
PUT (/:locale)/cabinets/:id(.:format) cabinets#update {:locale=>/en|de/}
DELETE (/:locale)/cabinets/:id(.:format) cabinets#destroy {:locale=>/en|de/}
role_permissions GET (/:locale)/roles/:role_id/permissions(.:format) permissions#index {:locale=>/en|de/}
POST (/:locale)/roles/:role_id/permissions(.:format) permissions#create {:locale=>/en|de/}
new_role_permission GET (/:locale)/roles/:role_id/permissions/new(.:format) permissions#new {:locale=>/en|de/}
edit_role_permission GET (/:locale)/roles/:role_id/permissions/:id/edit(.:format) permissions#edit {:locale=>/en|de/}
role_permission GET (/:locale)/roles/:role_id/permissions/:id(.:format) permissions#show {:locale=>/en|de/}
PUT (/:locale)/roles/:role_id/permissions/:id(.:format) permissions#update {:locale=>/en|de/}
DELETE (/:locale)/roles/:role_id/permissions/:id(.:format) permissions#destroy {:locale=>/en|de/}
roles GET (/:locale)/roles(.:format) roles#index {:locale=>/en|de/}
POST (/:locale)/roles(.:format) roles#create {:locale=>/en|de/}
new_role GET (/:locale)/roles/new(.:format) roles#new {:locale=>/en|de/}
edit_role GET (/:locale)/roles/:id/edit(.:format) roles#edit {:locale=>/en|de/}
role GET (/:locale)/roles/:id(.:format) roles#show {:locale=>/en|de/}
PUT (/:locale)/roles/:id(.:format) roles#update {:locale=>/en|de/}
DELETE (/:locale)/roles/:id(.:format) roles#destroy {:locale=>/en|de/}
locations_get_states GET (/:locale)/locations/get_states(.:format) locations#get_states {:locale=>/en|de/}
dashboard_index GET (/:locale)/dashboard/index(.:format) dashboard#index {:locale=>/en|de/}
store_map GET (/:locale)/store/map(.:format) store#map {:locale=>/en|de/}
root /(:locale)(.:format) store#hero {:locale=>/en|de/}
pages GET (/:locale)/pages(.:format) pages#index {:locale=>/en|de/}
POST (/:locale)/pages(.:format) pages#create {:locale=>/en|de/}
new_page GET (/:locale)/pages/new(.:format) pages#new {:locale=>/en|de/}
edit_page GET (/:locale)/pages/:id/edit(.:format) pages#edit {:locale=>/en|de/}
page GET (/:locale)/pages/:id(.:format) pages#show {:locale=>/en|de/}
PUT (/:locale)/pages/:id(.:format) pages#update {:locale=>/en|de/}
DELETE (/:locale)/pages/:id(.:format) pages#destroy {:locale=>/en|de/}
/*path(.:format) :controller#:action
/ :controller#:action
show.html.haml
- @page.ancestors.each do |page|
= link_to(t(page.name), page.url)
&gt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment