I want to display all the data present in the DB in same page where my form is present.I have saved one record.Please help me to show all the data after submit in that same page.
My code are as follows.
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
I want to show in the same index page after submitting the form using Rails 3.Please help me.
Aucun commentaire:
Enregistrer un commentaire