I''m trying to create an ajax form but I''m a little confused on
the
syntax I should use for REST.
I recently created a comments model which belongs to poems, and poem
has many comments.
I set up the routes like so:
[code=ruby]
map.resources :poems do |poems|
poems.resources :comments
end
[/code]
My Comments Controller
[code=ruby]
class CommentsController < ApplicationController
def new
@comment = Comment.new
end
def create
@comment = Comment.new(params[:comment])
respond_to do |format|
if @comment.save
flash[:notice] = ''Poem was successfully created.''
format.html { redirect_to comment_url(@poem, @comment) }
format.xml { head :created, :location => comment_url(@poem,
@comment) }
else
format.html { render :action => "new" }
format.xml { render :xml => @comment.errors.to_xml }
end
end
end
end
[/code]
But I''m rather confused on what I should be doing to create an ajax
form for comments, while viewing a poem.
poem show.rhtml
[code=ruby]
<p><% form_remote_tag(:update => "comments",
:url => { :action => :new },
:position => "top" ) %>
New Comment:
<%= text_field_tag :new %>
<%= submit_tag ''Save'' %>
<% end_form_tag -%></p>
[/code]
I did something like that, but I don''t think that''s right.
If anyone could point me in the right direction, I''d appreciate it.
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---