Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.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 使用简单表单视图erb生成表单_Ruby On Rails_Simple Form - Fatal编程技术网

Ruby on rails 使用简单表单视图erb生成表单

Ruby on rails 使用简单表单视图erb生成表单,ruby-on-rails,simple-form,Ruby On Rails,Simple Form,我正在尝试用简单的表单生成for。我在Gemfile中有gem,运行bundle安装和generate simple\u form:install 这是new.html.erb: <!DOCTYPE html> <html> <head> <title></title> </head> <body> <% simple_form_for @post do |f| %> <

我正在尝试用简单的表单生成for。我在Gemfile中有gem,运行
bundle安装
generate simple\u form:install

这是new.html.erb:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <% simple_form_for @post do |f| %>
    <%= f.input  :image %>
    <%= f.input  :caption %>
    <%= f.button :submit %>
    <% end %>
</body>
</html>
  • 我没有收到任何错误,但是当我用localhost加载视图时,我只看到一个纯白色的页面
  • 当我检查使用浏览器工具生成的视图时,我看到了所有html标记,但没有erb
  • 当我删除erb并编写类似于
    Test
    的内容时,我可以在浏览器中看到Test

我想不出我的代码出了什么问题,有什么想法吗?提前谢谢

我猜您错过了此代码中的
=
。 您可以按如下方式执行此操作:

<body>
 <%= simple_form_for @post do |f| %>
  <%= f.input  :image %>
  <%= f.input  :caption %>
  <%= f.button :submit %>
 <% end %>
</body>

我猜您在这段代码中错过了
=
。 您可以按如下方式执行此操作:

<body>
 <%= simple_form_for @post do |f| %>
  <%= f.input  :image %>
  <%= f.input  :caption %>
  <%= f.button :submit %>
 <% end %>
</body>


您可以参考此链接,在他们使用的示例中,您可以参考此链接,在他们使用的示例中,感谢您的回复。这与我已有的有什么不同?非常感谢,我认为第一行代码从来没有
=
。实际上我只是在检查erb中的其他循环示例,它们似乎没有
=
。我得用谷歌到处看看它是如何工作的谢谢你的回复。这与我已有的有什么不同?非常感谢,我认为第一行代码从来没有
=
。实际上我只是在检查erb中的其他循环示例,它们似乎没有
=
。我得用谷歌搜索一下,看看它是如何工作的
Rails.application.routes.draw do
  resources :posts
  root 'posts#index' 
end
<body>
 <%= simple_form_for @post do |f| %>
  <%= f.input  :image %>
  <%= f.input  :caption %>
  <%= f.button :submit %>
 <% end %>
</body>