Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.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 3显示同一页面中的所有数据_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 使用Rails 3显示同一页面中的所有数据

Ruby on rails 使用Rails 3显示同一页面中的所有数据,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,我想在表格所在的同一页中显示数据库中的所有数据。我已保存了一条记录。请帮助我在同一页中提交后显示所有数据 我的代码如下 views/users/index.html.erb {:action=>'create'}do | f |%> 姓名: 电邮: 内容: 名称 电子邮件 内容 控制器/用户\u controller.rb class UsersController“index” 其他的 闪存[:警报]=“无法创建用户” 闪光[:颜色]=“无效” 呈现“索引” 结束 结束 结束

我想在表格所在的同一页中显示数据库中的所有数据。我已保存了一条记录。请帮助我在同一页中提交后显示所有数据

我的代码如下

views/users/index.html.erb
{:action=>'create'}do | f |%>

姓名:

电邮:

内容:

名称 电子邮件 内容
控制器/用户\u controller.rb
class UsersController“index”
其他的
闪存[:警报]=“无法创建用户”
闪光[:颜色]=“无效”
呈现“索引”
结束
结束
结束
我想在使用Rails 3提交表单后在同一索引页中显示。请帮助我。

这应该可以

views/users/index.html.erb

<%= form_for :user,:url => {:action => 'create'} do |f| %>
<p>
    Name: <%= f.text_field :name %>
</p>
<p>
    Email: <%= f.email_field :email %>
</p>
<p>
    content: <%= f.text_field :content %>
</p>
<p>
     <%= f.submit 'Create' %>
</p>
<% end %>
<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
      <th>Content</th>
      <th colspan="3"></th>
    </tr>
  </thead>
  <tbody>
    <% @users.each do |u| %>
      <td> <%= u.name%> </td>
      <td> <%= u.email%> </td>
      <td> <%= u.content%> </td>
      <td> <%= link_to 'Show', u %> </td>
      <td> <%= link_to 'Edit', edit_user_path(u) %> </td>
      <td> <%= link_to 'Destroy', u, :method => :delete, :data => { :confirm => 'Are you sure?' } %> </td>
  </tbody>
</table>
class UsersController < ApplicationController
    def index
        @users=User.all
    end
    def create
        @users=User.new(params[:users])
        if @users.save
            flash[:notice]="User has created"
            flash[:color]="valid"
            redirect_to :action => 'index'
        else
            flash[:alert]="User couldnot created"
            flash[:color]="invalid"
            render 'index'
        end
    end
end
{:action=>'create'}do | f |%>

姓名:

电邮:

内容:

名称 电子邮件 内容 :delete,:data=>{:confirm=>'你确定吗?}%>
控制器/用户\u控制器.rb

<%= form_for :user,:url => {:action => 'create'} do |f| %>
<p>
    Name: <%= f.text_field :name %>
</p>
<p>
    Email: <%= f.email_field :email %>
</p>
<p>
    content: <%= f.text_field :content %>
</p>
<p>
     <%= f.submit 'Create' %>
</p>
<% end %>
<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
      <th>Content</th>
      <th colspan="3"></th>
    </tr>
  </thead>
  <tbody>
    <% @users.each do |u| %>
      <td> <%= u.name%> </td>
      <td> <%= u.email%> </td>
      <td> <%= u.content%> </td>
      <td> <%= link_to 'Show', u %> </td>
      <td> <%= link_to 'Edit', edit_user_path(u) %> </td>
      <td> <%= link_to 'Destroy', u, :method => :delete, :data => { :confirm => 'Are you sure?' } %> </td>
  </tbody>
</table>
class UsersController < ApplicationController
    def index
        @users=User.all
    end
    def create
        @users=User.new(params[:users])
        if @users.save
            flash[:notice]="User has created"
            flash[:color]="valid"
            redirect_to :action => 'index'
        else
            flash[:alert]="User couldnot created"
            flash[:color]="invalid"
            render 'index'
        end
    end
end
class UsersController“index”
其他的
闪存[:警报]=“无法创建用户”
闪光[:颜色]=“无效”
呈现“索引”
结束
结束
结束

我看不出有任何理由需要一个
用户。如果在索引中有新的
,您是否在任何地方使用它?好的,那么在接受的答案中,它需要被删除。