0 Replies - 463 Views - Last Post: 15 January 2009 - 01:43 PM

#1 juhania  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-November 08

need help setting up News based web site

Posted 15 January 2009 - 01:43 PM

hi every body

I am working in my project

and I have problem with it

my project is to build News web site
am using InstantRails , Ruby , html and database for news
my problem is in add comment code

when there is comment in database it is dispalyed
but I cant Add comment to the database ..

These are my codes :

In Controller
class CommentController < ApplicationController
   
   def list
	@comments = Comment.find(:all)
   end
   
   def new
	@comment = Comment.new
	
   end

   def create

	@comment = Comment.new(params[:comment])
	@comment.Date = Date.today
	
	
	  if @comment.save
			redirect_to :action => 'list'
	  else
			render :action => 'new'
	  end
   end

   def delete
	@id = params[:CommentID]
	Comment.delete(@id)
	  redirect_to :action => 'list'
   end
end




In View (list.rhtml):
<html>
<head>
</head>

<body>

<% if @comments.blank? %>
<p>There are not any comments currently in the system.</p>
<% else %>
<p>These are the current comments in our system</p>

<ul id="comments">
<% @comments.each do |c| %>
<li><%= link_to c.CommentBody, {:action => 'show', :CommentBody => c.ID} %>

<b> <%= link_to "Delete", {:action => 'delete', :CommentID => c.ID},
:confirm => "Are you sure you want to delete this Comment?" %></b>
</li>



<% end %>
</ul>
<% end %>
<p><%= link_to "Add new Comments", {:action => 'new' }%></p>
</body>
</html>



In View (new.rhtm):
<html>
<head>
</head>
<body>


<h1>Add new Comment</h1>

<% form_tag :action => 'create'  do %>

<p><label for="Comment_Body">Your Comment :)</label><br/>
<%= text_area 'comment', 'CommentBody' %></p>


<%= submit_tag "submit" %>
 
<% end  %>

<%= link_to "Back", {:action => 'list'} %>

</body>
</html>



and this is the DataBase for Comment table:
Table structure for table `comments`
-- 

CREATE TABLE `comments` (
  `NewsID` int(15) NOT NULL,
  `ID` int(15) NOT NULL auto_increment,
  `CommentBody` varchar(10000) NOT NULL,
  `Date` varchar(15) NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

-- 
-- Dumping data for table `comments`
-- 



please help me :$

Is This A Good Question/Topic? 0
  • +

Page 1 of 1