javascript - 平面网站转换为 RoR 网站

标签 javascript html css ruby-on-rails ruby

我有一个网站,目前仅使用 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/

相关文章:

JavaScript 文件不适用于 HTML

javascript - 表 td 内的 json2htmled jQuery 移动按钮看起来很旧,在按钮()/刷新后新按钮中有旧按钮

html - 链接的 css 和 javascripts 以内联形式出现

javascript - jQuery 将具有特定类别的所有图像调整为正方形

css - 删除 CSS 声明会破坏 block 中的其他声明,但仅适用于 Chrome 中的按钮

css - 如果我使用 XHTML 4.01 Strict,我应该避免使用 HTML5 不支持的标签吗?

javascript - 我在我的 ul 中添加了一个 li,虽然它有效,但会导致错误

javascript - 如何找出数组中包含的项目的位置?

javascript - 使用javascript在屏幕中间显示弹出窗口

html - 是否可以在 android 中使用 loadDataWithBaseURL() 方法显示图像?