【问题标题】:Ruby on Rails forms: missing template on submitRuby on Rails 表单:提交时缺少模板
【发布时间】:2010-03-01 13:58:46
【问题描述】:

我的控制器有两种方法:索引和搜索。

def index:渲染默认视图index.html.erb,并使用 YM4R/GM 显示默认地图。

def search:使用render index 呈现默认视图,但使用表单输入显示使用YM4R/GM 的自定义地图。

视图index.html.erb 包含部分视图_form.html.erb 和YM4R/GM 的@map.div。

通过默认渲染时地图显示正常,但提交到搜索方法时出现错误:
Template is missing. Missing template ym4r/gm_plugin/variables/_variable.erb in view path app/views。

奇怪的是,我昨天还在工作,直到我开始尝试使用form_remote_tag 提交我的表单。我开始使用这种类型的调用收到此错误,所以现在我已经将所有内容都改回来了(我认为),但我仍然收到错误。关于 Rails 如何呈现视图,我觉得有些地方我不明白。

【问题讨论】:

  • 我喜欢这些错误,首先一切正常,然后我更改某些内容并损坏,然后我撤消所有内容,但错误仍然存​​在:D 喜欢它!
  • 好的。我通过将render index 更改为render 'index' 来修复它。任何人都可以解释差异吗?
  • 是的,普通索引是在寻找一个叫index的方法,而字符串索引会寻找模板index.erb

标签: ruby-on-rails ruby forms


【解决方案1】:

正如您在此处所指出的,方法和字符串之间有一个重要区别。

# Call the index method, then render the result, whatever that is. Does not work as
# expected.
render(:action => index)

# Render using the index template
render(:action => 'index')

Ruby 在调用方法时非常轻松,因此不需要像 JavaScript 或 Perl 那样使用括号。

【讨论】:

  • 为了后人的好解释。
猜你喜欢
  • 2011-07-03
  • 2015-04-20
  • 1970-01-01
  • 2017-12-06
  • 1970-01-01
  • 2019-04-25
  • 2012-09-24
  • 1970-01-01
  • 2011-03-06
相关资源
最近更新 更多