从/shopqi/app/views/layouts/README.textile文件可以看出(如下代码所示),一共分这几大块儿
各个layout使用场景: # shopqi: 官网 # admin: 后台管理 # theme: 主题商店 # shop/checkout: 前台商店支付页面 # application.html.haml 用户登录
先看前端展示页与相关routes:
routes.rb
constraints(Domain::Shopqi) do scope module: :shopqi do # 官网 ...... root to: "home#page" scope "/tour" do # 功能演示 get '/' , to: 'home#tour' , as: :tour_intro get '/store' , to: 'home#store' , as: :tour_store get '/design' , to: 'home#design' , as: :tour_design get '/security', to: 'home#security', as: :tour_security get '/features', to: 'home#features', as: :tour_features end ...... end
constraints限定在Shopqi文件夹中
scope module: :shopqi controller的路径前面加上shopqi
scope "/tour" do 地址栏的路径前面加上/tour
都把矛头指向了controllers/shopqi/home/home_controller.rb,让我们来看看:
layout 'shopqi' expose(:plan_types){KeyValues::Plan::Type.all.reverse}
这是前两行的内容,第一行指定了布局,第二行用了decent_exposure插件和active_hash插件(见下面)。它返回plan_types,里面装的是顾客需要购买的商店类型基本信息(旗舰版,免费版...),sign_up的页面用到了这个变量
其它的静态页面跳转没有体现在home_controller中,直接跳过去了。
插件的使用:
- decent_exposure:使你的controller中的变量变得极其简洁。railscast有免费课程讲解
- active_hash:一个只读的ActiveRecord-esque基类,允许你使用一个散列,一个Yaml文件或一个自定义文件作为数据源
- model/key_value.rb运用active_hash写入了项目需要的硬编码
打开signup.html.haml,可以看到注册的入口
%a(href="/services/signup/new/free") %th.table-col-1.professional %a(href="/services/signup/new/professional") %th.table-col-2.business %a(href="/services/signup/new/business") %th.table-col-3.unlimited %a(href="/services/signup/new/unlimited")
让我们来到routes.rb中看看他们要去哪个页面
get '/signup' , to: redirect('/services/signup') get '/login' , to: 'home#login' scope "/services/signup" do get '/' , to: 'home#signup' , as: :services_signup # :confirmations, :omniauth_callbacks, :passwords, :registrations, :sessions, :unlocks devise_for :user, skip: [:sessions, :confirmations, :passwords], skip_helpers: true devise_scope :user do get "/new/:plan" , to: "registrations#new" , as: :signup get "/check_availability", to: "registrations#check_availability" post "/user" , to: "registrations#create" , as: :signup_user post "/verify_code" , to: "registrations#verify_code" # 获取手机校验码 end end
第一行:如果输入/signup,则跳到/services/signup
第二行:login的地址转换
第三行:下面所有浏览器显示地址都加上/services/signup
第四行:缺省蹦到home/signup页面,地址显示http://www.lvh.me:4000/services/signup
后面运用devise插件,方便的生成了用户注册等一系列动作
插件的使用:
插件的使用:
devise:rails3用户验证插件
registrations#new 跳转到 views/shopqi/registrations/new.html.haml 里面点击注册后
跳转到/shopqi/app/views/admin/home文件夹下,将显示此文件夹下一系列页面