
May 6th, 2012, 02:07 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 8
Time spent in forums: 1 h 54 m 52 sec
Reputation Power: 0
|
|
|
Posting comments to database via a form
So I am trying to submit a comment to an form that will display on the page. I want to be able to do this in ajax or prototype.
This is the html for the form.
Code:
<p id="notice"><%= notice %></p>
<p>
<b>Title:</b>
<%= @image.title %>
</p>
<p>
<%= image_tag @image.filename %>
</p>
<p>
<b>Likes:</b>
<span id="image_<%=@image.id%>_likes_count"><%= @image.likes %></span>
</p>
<form>
<label>Name:</label>
<input type="text" name="name" />
<label>Comment:</label>
<input type="text" name="comment" />
<input type="submit" value="Submit" name="submit" class="post" />
</form>
<div id="comments">
<h2>Comments displayed here</h2>
<%= render :partial => "shared/comment", :collection => @image.comments%>
</div
<%= link_to 'Like', like_image_path(@image), :method => :post %> |
<%= link_to 'Edit', edit_image_path(@image) %> |
<%= link_to 'Back', images_path %>
This is the db for create_commentables
Code:
class CreateCommentables < ActiveRecord::Migration
def self.up
create_table :commentables do |t|
t.integer :commentator_id
t.integer :resource_id
t.string :resource_type
t.integer :commentator_id
t.string :commentator_type
t.text :comment
t.timestamps
end
end
def self.down
drop_table :commentables
end
end
|