# Someone has to know how to do this

**URL:** <https://www.ruby-forum.com/t/someone-has-to-know-how-to-do-this/82591>\
**Category:** Rails\
**Created:** [March 16, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/someone-has-to-know-how-to-do-this/82591 "2006-03-16T17:01:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [March 16, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/someone-has-to-know-how-to-do-this/82591/1 "2006-03-16T17:01:01Z")

</div>

I’ve got my site posting comments with ajax, but I can’t seem to handle  
the callback correctly.

Do I just put what I want returned in the “comments.rhtml” file? I’ve  
been trying to do this, but am having no luck.

If I have the parameters for the comments, I should be able to single  
them out, but I’m not sure how to do it. This is what I mean:

\<%=params[:comments]%\> #returns name, site, comment, but not  
individually.

How can I do this essentially (without getting errors),

\<%=params[:comments.name]%\>  
\<%=params[:comments.site]%\>  
\<%=params[:comments.created\_at]%\>  
\<%=params[:comments.entry]%\>

Also, when I try to use strftime in “comments.rhtml” it says that it’s  
undefined.

I don’t even know if the above things that I mentioned are even the  
right way to go about it, I just don’t know how to do it.

The comments are saving to the database fine, but I have to refresh the  
page to get it to show up. Also, I would like to use  
“Effect.Appear(‘new-comment’)” oncomplete. This doesn’t seem to be  
working either.

Can someone tell me how to display the comment after an Ajax submission?

Please HELP!

Thanks!

---

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [March 16, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/someone-has-to-know-how-to-do-this/82591/2 "2006-03-16T17:12:56Z")

</div>

On Thu, 2006-03-16 at 17:01 +0100, ryan wrote:

> individually.
> 
> How can I do this essentially (without getting errors),
> 
> \<%=params[:comments.name]%\>  
> \<%=params[:comments.site]%\>  
> \<%=params[:comments.created\_at]%\>  
> \<%=params[:comments.entry]%\>

* * *

I would think that these should be…

## \<%= params[:comments][:name] %\> \<%= params[:comments][:site] %\> \<%= params[:comments][:created\_at] %\> \<%= params[:comments][:entry] %\>

> Also, when I try to use strftime in “comments.rhtml” it says that it’s  
> undefined.

* * *

you should probably show how your using it but I would think that this  
should work…

## \<%= (params[:comments][:created\_at]).strftime("%m/%d/%Y") %\>

> I don’t even know if the above things that I mentioned are even the  
> right way to go about it, I just don’t know how to do it.
> 
> The comments are saving to the database fine, but I have to refresh the  
> page to get it to show up. Also, I would like to use  
> “Effect.Appear(‘new-comment’)” oncomplete. This doesn’t seem to be  
> working either.
> 
> Can someone tell me how to display the comment after an Ajax submission?

* * *

I’ll let someone else help with that.

Craig

---

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [March 16, 2006, 7:04pm UTC](https://www.ruby-forum.com/t/someone-has-to-know-how-to-do-this/82591/3 "2006-03-16T19:04:52Z")

</div>

I THINK CRAIG NAILED IT ON THE HEAD RYAN !  
THANKS CRAIG. MY CAPSLOCKS KEY MUST BE STUCK 😃

---

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [March 16, 2006, 7:09pm UTC](https://www.ruby-forum.com/t/someone-has-to-know-how-to-do-this/82591/4 "2006-03-16T19:09:18Z")

</div>

Dylan S. wrote:

> I THINK CRAIG NAILED IT ON THE HEAD RYAN !  
> THANKS CRAIG. MY CAPSLOCKS KEY MUST BE STUCK 😃

Yes, I can access the name, site, and entry that way, but not the  
“created\_at” attribute.

How can I access this variable? I guess since it’s automatically  
created, it doesn’t show up in the params?

Also, how can I return a count one more than the last comment?  
Essentially, displaying #1, #2, #3 with each comment.

Right now, on page load, I’m incrementing a counter inside of the for  
loop which iterates through the comments, but since I’m trying to do  
ajax, this part won’t be involved in the for loop.

please help again!

---

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [March 16, 2006, 7:18pm UTC](https://www.ruby-forum.com/t/someone-has-to-know-how-to-do-this/82591/5 "2006-03-16T19:18:14Z")

</div>

OK - I will bite, even if you posted the topic in caps.

The return from the AJAX call will need to update a div in your page.  
Try to get it working by just returning  
render\_text ‘done’. When you see your page updating the div with ‘done’  
you can then try returning the actaully content that you want displayed.

I find the best way to do this is using a partial. To illustrate, here  
is an AJAX action from the app that I am currently working on.

def set\_priority  
requirement = Requirement.find( params[:id] )  
requirement.increment\_priority  
requirement.save  
vendors = Vendor.find( :all )  
render :partial =\> “requirements”, :locals =\> { :requirement =\>  
requirement, :vendors =\> vendors }  
end

and here is the the rhtml from the original page.

\<% for feature in @features %\>  
\<% requirement = feature.requirement( @project.id) %\>  
\<%= render( :partial =\> “requirements”, :locals =\> { :requirement =\>  
requirement, :vendors =\> @vendors } ) %\>  
\<% end %\>

Hope this helps.
