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

On May 9, 2009, at 13:10, Mohit Sindhwani <t...@onghu.com> wrote:

Mohit Sindhwani wrote:
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?
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.
_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant
_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to