Thanks lot to all of you to reply .
I follow below link which work perfectly for me.
The link which i have given up is have full code. Below i have shown only
confusing code to me.
I firstly clear that i seen first time respond_to keyword and different type of formats .
I know code is working perfectly when i do manual testing, but technically i am zero.
Q1 I don' t understood why there is create.js.erb and destroy.js.erb require?
Q2 What is this format.js in controller ?Is this line call to create.js.erb ?
Q3 below code confuse me .
If record save than call goes to format.html which send us to index page than when call goes to format.js ?
Or it work line by line ?i am just guessing .
#################code#####################################################33
respond_to do |format|
if @post.save
format.html { redirect_to(posts_url,
:notice => 'Post was successfully created.') }
format.js
else
format.html { redirect_to(posts_url) }
end
end
end
#######################code##################################################
########################PostsController######################
class PostsController < ApplicationController
def index
@posts = Post.all
@post = Post.new
respond_to do |format|
format.html
end
end
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to(posts_url,
:notice => 'Post was successfully created.') }
format.js
else
format.html { redirect_to(posts_url) }
end
end
end
def destroy
@post = Post.find(params[:id])
@post.destroy
respond_to do |format|
format.html { redirect_to(posts_url) }
format.js
end
end
end
################################################################################
################create.js.erb###############################################
$('#posts').prepend('<%= escape_javascript(render(@post)) %>');
$('#posts > li:first').effect('highlight', {}, 3000);
$('#post_form > form')[0].reset();
#################################################################################
######################destroy.js.erb#################################
$('#<%= dom_id(@post) %>').css('background', 'red');
$('#<%= dom_id(@post) %>').hide("fade", {}, 1500);
##################################################################################
Waiting for reply.
Thanks
Best Regards
Fahim Babar Patel