Forum: Ruby on Rails SOMEONE HAS TO KNOW HOW TO DO THIS

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1e2dd87a31c5d3e07adc9efa375f4dc4?d=identicon&s=25 ryan (Guest)
on 2006-03-16 17:01
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!
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-03-16 17:12
(Received via mailing list)
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
Ff82af3238a57fbd1212832ec1a19f28?d=identicon&s=25 Dylan Stamat (Guest)
on 2006-03-16 19:04
(Received via mailing list)
I THINK CRAIG NAILED IT ON THE HEAD RYAN !
THANKS CRAIG.  MY CAPSLOCKS KEY MUST BE STUCK :D
1e2dd87a31c5d3e07adc9efa375f4dc4?d=identicon&s=25 ryan (Guest)
on 2006-03-16 19:09
Dylan Stamat wrote:
> I THINK CRAIG NAILED IT ON THE HEAD RYAN !
> THANKS CRAIG.  MY CAPSLOCKS KEY MUST BE STUCK :D

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!
Aa575b7606897a056f073f0f148804dd?d=identicon&s=25 Gareth Reeves (reevesg)
on 2006-03-16 19:18
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.
This topic is locked and can not be replied to.