Ajax

def new
@answer = Answer.new
respond_to do |format|
format.js do
render :update do |page|
page.hide “add_answer_link_for_post_#{@post.id}”
page.replace_html “new_answer_form_for_post_#{@post.id}”,
:partial => “new”
end
end
end
end

_new.html.erb:
<% remote_form_for(:answer, :url => answers_path) do |form| %>

New Answer <%= form.text_area :body, :rows => 10, :cols => 40 %> <%= submit_tag "Create" %> <% end %>

def create
@answer = Answer.new(params[:answer])
@answer.user = User.find(session[:user_id])
@answer.post = @post
respond_to do |format|
if @answer.duplicate? or @post.answers << @answer
format.js do
render :update do |page|
page.replace_html “answers_for_post_#{@post.id}”,
:partial => “answers/answer”,
:collection => @post.answers
page.show “add_answer_link_for_post_#{@post.id}”
page.hide “new_answer_form_for_post_#{@post.id}”
end
end
else
format.js { render :nothing => true }
end
end
end

_answer.html.erb


<% if logged_in? and answer.authorized? (User.find(session[:user_id])) %> <%= link_to_remote "(delete)", :url => answer_path(answer.post.blog, answer.post, answer), :method => :delete, :confirm => 'Are you sure?' %> <% end %>

ABove is the code that uses AJAX calls…but gives errors wen run…can
any 1 help me in implementing AJAX in rails…i need it urgent

Can you post the error message?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs