使用 Rails 3 在同一页显示所有数据
Display all the data in the same page using Rails 3
我想在我的表单所在的同一页面中显示数据库中存在的所有数据 present.I 已保存一个 record.Please 帮助我在同一页面中显示提交后的所有数据。
我的代码如下
views/users/index.html.erb
<%= form_for :users,: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>
</tbody>
</table>
controller/users_controller.rb
class UsersController < ApplicationController
def index
@users=User.new
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
我想在使用 Rails 提交表单后显示在同一索引页中 3.Please 帮助我。
这应该有效
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>
controller/users_controller.rb
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
我想在我的表单所在的同一页面中显示数据库中存在的所有数据 present.I 已保存一个 record.Please 帮助我在同一页面中显示提交后的所有数据。
我的代码如下
views/users/index.html.erb
<%= form_for :users,: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>
</tbody>
</table>
controller/users_controller.rb
class UsersController < ApplicationController
def index
@users=User.new
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
我想在使用 Rails 提交表单后显示在同一索引页中 3.Please 帮助我。
这应该有效
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>
controller/users_controller.rb
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