I am using form_tag in my create.html.erb file. Under this form_tag there is a button. Now I wish that after clicking the button the page will be refreshed only ,I dont want to redirect anywhere . So what should I write in my form tag as path?
For session controller my view/sessions/create.html.erb file is:
<h4>Database contents here:</h4>
<table>
<tr>
<th>ID</th>
<th>AGE</th>
<th>NAME</th>
</tr>
<% @data.each do |data| %>
<tr>
<td><%= data.id %></td>
<td><%= data.age %></td>
<td><%= data.name %></td>
</tr>
<% end %>
</table>
<div>
<%= form_tag :method => :get do %>
<%= button_tag type: 'submit' do %>
<%= content_tag :div do%>
<h4>View Data </h4><h4><%= @num %></h4>
<% end %>
<% end %>
<% end %>
</div>
And my contollers/sessions_controller file is:
class SessionsController < ApplicationController
def new
end
def index
end
def create
user = User.authenticate(params[:email], params[:password])
@data=Information.all
@num=Information.count()
@tym=Time.now.getutc
if user
session[:user_id] = user.id
#redirect_to root_url, :notice => "Logged in!"
#this part is for showing the content of the information table
respond_to do |format|
format.html
format.xml { render xml: @data }
end
else
flash.now.alert = "Invalid email or password"
render "new"
end
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "Logged out!"
end
end
Aucun commentaire:
Enregistrer un commentaire