gpt4 book ai didi

ruby-on-rails - 简单的 Ruby on Rails 应用

转载 作者:行者123 更新时间:2023-12-04 05:58:29 26 4
gpt4 key购买 nike

我想编写简单的应用程序,带有索引和关于页面,不使用 db,所有文本都将在 View 中。但是我不能调用我的 Controller 方法来改变 View 。
这是 Controller (home_controller.rb)

class HomeController < ApplicationController

def index
end

def about
end

end

布局:
!!!
%html
%head
%title Title
= stylesheet_link_tag "application"
= javascript_include_tag "application"
= csrf_meta_tags
%body
.wrapper
= yield
.footer

首页索引 View :
%h2 Index
%h1
This is example page
%p
= link_to "Home", root_path
= link_to "About", :controller => "home", :action => "index"
%p
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

关于 View :
%h2 About
%h1
This is about page
%p
= link_to "Home", root_path
= link_to "About", :controller => "home", :action => "about"
%p
Lorem ipsum

在 routes.rb 我有 root :to => 'home#index'
当我调用我的域时,我会得到索引,当我写:domain/home/index 我得到

No route matches [GET] "/home/index"



当我打电话时,它是一样的,我如何调用我的页面?
rake 路线给我:

root / {:controller=>"home", :action=>"index"}

最佳答案

您也应该定义这些路由。它们不会自动出现。

例如,您可以在默认生成的 routes.rb(最后)中找到以下内容。

  # This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'

取消注释,您应该可以访问 /home/index/home/about .

关于ruby-on-rails - 简单的 Ruby on Rails 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9227221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com