Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 我应该在哪里创建rails视图-rails 4.0_Ruby On Rails_Ruby_Views - Fatal编程技术网

Ruby on rails 我应该在哪里创建rails视图-rails 4.0

Ruby on rails 我应该在哪里创建rails视图-rails 4.0,ruby-on-rails,ruby,views,Ruby On Rails,Ruby,Views,我有一个rails应用程序,其主页如下: www.person.com 然后我有了一个model-Person,他有一个id属性 如果我希望基于该ID创建一个视图,并且我希望URL如下所示: www.person.com/{person.id},或www.person.com/1 我应该在哪里创建我的视图,我应该给它起什么名字?是否应该是Views/Person/index.html.erb?而是在Views/Person/code>中创建show.html.erb 您还需要在persons\u

我有一个rails应用程序,其主页如下:

www.person.com

然后我有了一个model-
Person
,他有一个
id
属性

如果我希望基于该ID创建一个视图,并且我希望URL如下所示:

www.person.com/{person.id}
,或
www.person.com/1


我应该在哪里创建我的视图,我应该给它起什么名字?是否应该是
Views/Person/index.html.erb?

而是在
Views/Person/code>中创建
show.html.erb

您还需要在
persons\u controller.rb
中创建控制器方法:

def show
  # Insert options for person's page here
end
神奇发生在
routes.rb中,您将在其中为该
show
定义路由:

resources :persons, :path => '', :path_names => {:show => '/:id'}

棒极了——作为rails的新手,解释所有的片段都很有帮助。谢谢