Fix some bugs

This commit is contained in:
manson 2014-04-14 11:27:09 +08:00
parent 3c8f4bcb53
commit 5eae7b8346
13 changed files with 29 additions and 13 deletions

View File

@ -3,4 +3,4 @@
require File.expand_path('../config/application', __FILE__)
OrbitStore::Application.load_tasks
Orbit::Application.load_tasks

View File

@ -19,7 +19,7 @@ class PagesController < ApplicationController
def home
@manifest = @key
@dataApi = nil
page = Page.where(:number => 0,:page_id => "").first
page = Page.first
OrbitHelper.set_params params
OrbitHelper.set_site_locale locale
render :html => render_final_page("home",page).html_safe
@ -144,7 +144,7 @@ class PagesController < ApplicationController
def get_view
page = Page.find(params[:id])
if page.page_id == "" && page.number == 0
if page == Page.first
@view = File.join(Rails.root, 'app', 'templates', "#{@key}", 'home/index.html.erb')
else
module_name = page.module.downcase.pluralize
@ -158,6 +158,7 @@ class PagesController < ApplicationController
@url = "/#{params[:page][:page_id]}"
else
page = Page.find(params[:page][:parent_page])
page.url = page.url.nil? ? "" : page.url
@url = page.url + "/#{params[:page][:page_id]}"
end
p = params.require(:page).permit(:number, :page_id, :module, :parent_page, name_translations: [:en, :zh_tw])

View File

@ -94,6 +94,7 @@ module ApplicationHelper
(data[keys[0]].kind_of?(Array) ? data[keys[0]] : data[keys[1]]).each do |item|
el = wrap_element.inner_html
item.each do |key,value|
value = value.nil? ? "" : value
el = el.gsub("{{#{key}}}",value)
el = el.gsub("%7B%7B#{key}%7D%7D",value)
end
@ -104,6 +105,7 @@ module ApplicationHelper
html = doc.to_html
if keys[1]
(data[keys[1]].kind_of?(Array) ? data[keys[0]] : data[keys[1]]).each do |key,value|
value = value.nil? ? "" : value
html = html.gsub("{{#{key}}}",value)
html = html.gsub("%7B%7B#{key}%7D%7D",value)
end
@ -119,6 +121,7 @@ module ApplicationHelper
data = controller.send("#{params[:target_action]}")
el = wrap_element_html
data.each do |key,value|
value = value.nil? ? "" : value
el = el.gsub("{{#{key}}}",value)
el = el.gsub("%7B%7B#{key}%7D%7D",value)
end

View File

@ -26,6 +26,7 @@ module PagesHelper
(data[keys[0]].kind_of?(Array) ? data[keys[0]] : data[keys[1]]).each do |item|
el = wrap_element.inner_html
item.each do |key,value|
value = value.nil? ? "" : value
el = el.gsub("{{#{key}}}",value)
el = el.gsub("%7B%7B#{key}%7D%7D",value)
end

View File

@ -2,16 +2,21 @@
extend ActiveSupport::Concern
included do
index({ uid: 1}, { unique: true })
validates_uniqueness_of :uid
before_create :generate_uid
end
def to_param
[self.title.gsub(/[ "'*@#$%^&()+=;:.,?>|\\<~_!]/,'-').gsub(/-{2,}/,'-'), self.uid].join("-")
(self.slug_title.gsub(/[ "'*@#$%^&()+=;:.,?>|\\<~_!:,、。!?;「」〈〉【】/]/,'-')+"-"+self.uid).gsub(/-{2,}/,'-') rescue "-"+self.uid
end
private
def generate_uid
self.uid = rand(36**8).to_s(36)
self.uid = rand(10**8).to_s
generate_uid if self.class.where(:uid=>self.uid).size > 0
end
end

View File

@ -13,7 +13,7 @@ require "mongoid/railtie"
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module OrbitStore
module Orbit
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers

View File

@ -2,4 +2,10 @@
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
OrbitStore::Application.initialize!
Orbit::Application.initialize!
if Page.count == 0
home = Page.new
home.name_translations = {:en=>"home",:zh_tw=>"首頁"}
home.url = ""
home.save
end

View File

@ -1,4 +1,4 @@
OrbitStore::Application.configure do
Orbit::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on

View File

@ -1,4 +1,4 @@
OrbitStore::Application.configure do
Orbit::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.

View File

@ -1,4 +1,4 @@
OrbitStore::Application.configure do
Orbit::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's

View File

@ -9,4 +9,4 @@
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
OrbitStore::Application.config.secret_key_base = 'acc6ffc5a7d360c9cf2a7bdb4ddf9a897942ec6767413a5c0324a0fa8b86197a96298288a66bd46d8770d8b6edf509aad65716961c2c364ce006b475e6cfd418'
Orbit::Application.config.secret_key_base = 'acc6ffc5a7d360c9cf2a7bdb4ddf9a897942ec6767413a5c0324a0fa8b86197a96298288a66bd46d8770d8b6edf509aad65716961c2c364ce006b475e6cfd418'

View File

@ -1,3 +1,3 @@
# Be sure to restart your server when you modify this file.
OrbitStore::Application.config.session_store :cookie_store, key: '_orbit_store_session'
Orbit::Application.config.session_store :cookie_store, key: '_orbit_store_session'

View File

@ -1,4 +1,4 @@
OrbitStore::Application.routes.draw do
Orbit::Application.routes.draw do
get "/pages/edit_view" => "pages#edit_view"
get "/pages/preview" => "pages#preview"