应用程序看不到我的观点

应用程序看不到我的观点

本文介绍了Rails 应用程序看不到我的观点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在在铁路上已经有一段时间了,这是我一直遇到的问题:

I've on a while on rails now and here's the problem I've been having on and on:

当我通过以下方式创建控制器时:

When I create a controller through:

"rails 生成控制器 ControllerName ViewName"

我让一切都按我的意愿工作,但如果出于某种原因我通过以下方式创建控制器:

I get everything working as I want but if for some reason I create the controller through:

"rails 生成控制器 ControllerName"

然后只需将 ViewName.html.erb 添加到与我的控制器同名的视图内的文件夹中,事情就会出错.所以具体的情况是我写的:

and then just add ViewName.html.erb to the folder inside views that has the same name as my controller things would go wrong.So the concrete case is me writing:

rails 生成控制器主题列表显示.

为我创造:

1.controllers>subjects_controller.rb
2.views>subjects>list.html.erb
3.views>subjects>show.html.erb

所以这一切都很好.但正如我已经说过的,如果我需要另一个视图;让我们说新",我只是在其他 *.html.erb 文件旁边添加new.html.erb"一个动作:

So this whole thing works fine.But as I already said if I need another view; let's say "new" I just add "new.html.erb" next to the other *.html.erb files and an action:

定义新

结束

到我的 subjects_controller.rb 那么它就行不通了.前两个视图会继续工作,但在命令行之外创建的任何其他*html.erb"都不会.

to my subjects_controller.rb then it won't work.The two previous views would keep working but any other "*html.erb" created outside the command line wouldn't.

是否还有其他地方可以存储有关视图的信息?.

Is there anywhere else where info about views is being stored?.

我是 Windows 7 用户(32 位).Rails 版本 = 3.0.3.网络服务器=WEBrick.文本编辑器 = 电子文本编辑器

I'm a Windows 7 user (32 bit).Rails version=3.0.3. WebServer=WEBrick.Text editor = E-TextEditor

推荐答案

这很可能是由于您的路由没有正确配置造成的.所以看看你的 routes.rb 的内容会很有帮助

This is most likely caused by your routes not being correctly configured. So it would be helpful to see the content of your routes.rb

在您的情况下,我认为配置路由的最佳方法是使用资源映射:

In your case I think the best way to configure the routes is to use the resources mapping:

resources :subjects

这将默认为标准 RESTful 操作创建路由:index、:show、:edit、:update、:new、:create 和 :destroy.

This will by default create routing for the standard RESTful actions :index, :show, :edit, :update, :new, :create and :destroy.

有关路由的更多详细信息,我建议Rails 从外向内路由

For more detailed information about the routing, I would recommend Rails Routing from the Outside In

这篇关于Rails 应用程序看不到我的观点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 14:06