I am making one application and i want to open one registration form in popup window when user will click on a link.I have done some coding but still unable to open it.Please check my codes explained below and let me to know where i did the mistake and how to resolve this.
views/users/index.html.erb
<table>
<tr>
<th>Name</th>
<th>Email id</th>
<th>Password</th>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.email %></td>
<td><%= user.Password %></td>
</tr>
<% end %>
</table>
<p>
<%= link_to 'New Task', users_new_path, :id => 'onclick',remote: true %>
</p>
<div id="task-form" style="display:none;"></div>
views/users/new.js.erb
$('#task-form').html("<%= j (render 'form') %>");
$(document).ready(function() {
$("#onclick").click(function() {
$("#contactdiv").css("display", "block");
});
$("#contact #cancel").click(function() {
$(this).parent().parent().hide();
});
});
views/users/new.html.erb
<%= render 'form' %>
users_controller.rb
class UsersController < ApplicationController
def index
@users=User.all
respond_to do |format|
format.html
format.json
end
end
def new
@users=User.new
end
def create
@users=User.new(params[:users])
if @users.save
flash[:notice]="User has created successfully"
flash[:color]="valid"
redirect_to 'index'
else
flash[:alert]="User couldnot created"
flash[:color]="invalid"
render 'new'
end
end
end
views/users/_form.html.erb
<div id="contactdiv">
<%= form_for :users,:url => {:action => 'create'},:html => {:class => 'form',:id => 'contact'} do |f| %>
<img src="/assets/closebtn.png" class="img" id="cancel"/>
<p>
Name:<%= f.text_field :name,placeholder:"Enter your name" %>
</p>
<p>
Email Id:<%= f.email_field :email,placeholder: "Enter your email" %>
</p>
<p>
Password:<%= f.password_field :password,placeholder:"Enter your password" %>
</p>
<p>
<%= f.submit "Submit" %>
</p>
<input type="button" id="cancel" value="Cancel"/>
<% end %>
</div>
Please help me.
Aucun commentaire:
Enregistrer un commentaire