我有一个html主页,我创建了一些CSS和JS代码。我想将它作为主页包含在我的ruby应用程序中。在我的config / routes.rb中,我有这个:
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
root :to => 'first_controller#index', :as => 'first_controller'
在我的first_controller
我有这个:
class FirstControllerController < ApplicationController
def index
@users = User.all
end
end
我可以创建一个重定向到我的html文件的def home
方法吗?
@users = User.all
是来自图书即时阅读的代码,它教你如何构建一个ruby应用程序,我会根据自己的需要进行修改。
THX
答案 0 :(得分:0)
你可以做到
class FirstControllerController < ApplicationController
def index
@users = User.all
end
def home
render :template => "relative/path/from/views", :layout => false
end
end
此外,由于它是普通的html,你可以让rails缓存它。在控制器中添加caches_page :home
修改:格式化