我有一个网站,目前仅使用 HTML/CSS 和一些 JavaScript 构建。我现在正在寻找这个现有网站并将其变成一个 Rails 应用程序。我有几个目录(Home、About、Projects 等),每个目录都有自己的 index.html 和 css/js 文件。
我现在正在学习 RoR 并想将它变成一个 Rails 应用程序。请帮助完成此过程。
最佳答案
只需这样做:
#app/models/page.rb
Class Page < ActiveRecord::Base
#schema ->
id
title
content
created_at
updated_at
scope :not, ->(title) { where('pages.title != ?', title) }
end
#app/controllers/pages_controller.rb
Class Pages < ApplicationController
def show
@page = Page.find_by title: params[:title]
end
end
#app/views/pages/show.html.haml
= @page.content
#config/routes.rb
root to: "pages#show", title: "home"
begin
for page in Page.all.not("home")
get "#{page.title}" => "pages#show", title: page.title
end
rescue
end
这允许您将所有页面存储在 Page
模型 (db) 中,并为每个页面创建路由。非常基本,但正是您所需要的
关于javascript - 平面网站转换为 RoR 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22886906/