在Rails中,什么是处理大量静态页面的
要不有大量静态页面的最佳途径。
严重的是,Rails是现存的最强大的,动态的和全面的应用框架之一,并且想用静态页面来填补呢?
你会是最好的制作basic CMS
与markdown
填充它:
#app/models/page.rb
class Page < ActiveRecord::Base
#columns id | title | body | created_at | updated_at
#has_many :categories -> the power of Rails; you can add whatever you want!
end
#app/controllers/pages_controller.rb
class PagesController < ApplicationController
before_action :find_page, only: [:show]
def index
@pages = Page.all
end
def show
end
private
def find_page
@page = Page.find params[:id]
end
end
这会给你创建一组简单的路由能力:
#config/routes.rb
root to: "pages#index"
resources :pages, only: [:index, :show]
- -
你不得不自己填充数据库,或者如果哟u想创建一个非常简单的管理方面,我强烈建议使用Devise
:
#config/routes.rb
namespace :admin do
root to: "pages#index"
resources :pages, path: "" #-> yoururl.com/admin/...
end
这会给你创造一个CRUD
admin/pages
控制器的能力:
#app/controllers/admin/pages_controller.rb
class PagesController < ApplicationController
before_action :set_page, only: [:edit, :update, :show, :destroy]
before_action :authenticate_user!
def index
@pages = Page.all
end
def edit
end
def update
@page.update page_params
end
def destroy
@page.destroy page_params
end
def show
end
private
def page_params
params.require(:page).permit(:title, :body)
end
end
然后你只需要把你的网页放到数据库中,让你通过你的路线给他们打电话。如果您需要自定义路线,请使用friendly_id
来创建它们。
静态页面上的链接怎么样? –
这就是我说CSV或Excel的原因。 –