# About Comments Extension

**URL:** <https://www.ruby-forum.com/t/about-comments-extension/167587>\
**Category:** Radiant CMS\
**Created:** [May 9, 2009, 5:57pm UTC](https://www.ruby-forum.com/t/about-comments-extension/167587 "2009-05-09T17:57:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [May 9, 2009, 5:57pm UTC](https://www.ruby-forum.com/t/about-comments-extension/167587/1 "2009-05-09T17:57:25Z")

</div>

Hi, I have just started to use the Comments Extension. One of the  
things that I have noticed is that the comments extension has always  
mentioned in the readme that:

Relative urls will not work on comment pages if they fail validation,  
since the page gets re-rendered at a (probably) different level of the  
hierarchy. Always use absolute urls and you won’t have any issues.

I don’t know what to make of this. I find that even if the comment post  
is successful, relative URLs may not work. I was wondering how to  
resolve it. For this, I changed the following line in the  
comments\_controller.rb \> create:

redirect\_to “#{@page.url}comments#comment-#{comment.id}”

to:  
redirect\_to “#{@page.url}”

This way, it should just redirect to the page on which the comment was  
posted. It seems to work… but can someone confirm if that is indeed  
the correct way to deal with it?

Cheers,  
Mohit.  
5/9/2009 | 11:25 PM.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [May 9, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/about-comments-extension/167587/2 "2009-05-09T19:11:49Z")

</div>

Mohit S. wrote:

> to resolve it. For this, I changed the following line in the  
> comments\_controller.rb \> create:
> 
> redirect\_to “#{@page.url}comments#comment-#{comment.id}”
> 
> to:  
> redirect\_to “#{@page.url}”
> 
> This way, it should just redirect to the page on which the comment was  
> posted. It seems to work… but can someone confirm if that is indeed  
> the correct way to deal with it?  
> I have been further playing and have spent quite a while copying back  
> code from Radiant’s controllers into the Comments Controller to see what  
> works. This is what the create function looks like now and it seems  
> like it works. Could someone help me see if my assumption is correct?  
> Is this how we should modify the create action on the comments  
> controller to fix it in case validation fails? It appears that relative  
> URLs are also rendering correctly now.

def create  
comment = @page.comments.build(params[:comment])  
comment.request = request  
comment.save!

```
ResponseCache.instance.clear
if Radiant::Config['comments.notification'] == "true"
  if comment.approved? ||

```

Radiant::Config[‘comments.notify\_unapproved’] == “true”  
CommentMailer.deliver\_comment\_notification(comment)  
end  
end

```
flash[:selected_comment] = comment.id
#Changed the line below to deal with wrong rendering of relative

```

links even when validation passes  
#redirect\_to “#{@page.url}comments#comment-#{comment.id}”  
redirect\_to “#{@page.url}”  
rescue ActiveRecord::RecordInvalid  
@pg = Page.find\_by\_url(@page.url)  
@pg.last\_comment = comment  
unless @pg.nil?  
#process\_page(@page) \<-- replaced this with the part below since  
process\_page is private in SiteController  
@pg.process(request, response)  
@cache.cache\_response(url, response) if request.get? and live?  
and @pg.cache?  
@performed\_render = true  
else  
render :template =\> ‘site/not\_found’, :status =\> 404  
end  
end

Any help would be greatly appreciated!

Cheers,  
Mohit.  
5/10/2009 | 1:10 AM.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [May 9, 2009, 8:12pm UTC](https://www.ruby-forum.com/t/about-comments-extension/167587/3 "2009-05-09T20:12:12Z")

</div>

Mohit  
Thanks for looking into this. I don’t have time at the moment to look  
at this buy I’ll try to get to it in the next few days.

Be sure to write some specs to test it out. I plan to move all  
Test::Unit stuff to Rspec.

Jim
