Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/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操作不渲染_Ruby On Rails - Fatal编程技术网

Ruby on rails Rails操作不渲染

Ruby on rails Rails操作不渲染,ruby-on-rails,Ruby On Rails,这是我的index.html.erb: <%= render :action => 'new' %> <% unless @posts.empty? %> <%= render @posts %> <% end %> 此外,如果我将其替换为仅,则会出现以下错误: undefined method `include?' for :new:Symbol 但是它应该允许我使用Rails 2.3.8隐式地呈现操作 如果有人能解释这两件事,我

这是我的
index.html.erb

<%= render :action => 'new' %>

<% unless @posts.empty? %>
  <%= render @posts %>
<% end %>
此外,如果我将其替换为仅
,则会出现以下错误:

undefined method `include?' for :new:Symbol
但是它应该允许我使用Rails 2.3.8隐式地呈现操作


如果有人能解释这两件事,我将不胜感激。

只是一个想法,但我怀疑雇员再培训局会将这两个街区视为一条线。正如您可能知道的,在Ruby中,在行尾添加“除非”或“如果”条件是非常惯用的


您可能希望在“除非”之前添加换行符,但在之后,您应该只渲染视图中的部分。由于您需要多个视图中的内容,因此可以将new.html.erb的内容转换为部分内容(例如,_new.html.erb),然后


来自new.html.erb以及index.html.erb。render:action=>“actionname”用于从控制器内呈现另一个操作的模板

请注意,为每个模型创建一个_form.html.erb partial是一种常见的习惯用法,并在需要从其他地方添加或编辑模型实例时使用它。这在这种情况下也很有用。然后从索引、新建和编辑中呈现部分表单

undefined method `include?' for :new:Symbol
<%= render 'new' %>