Getting json data to div and partial after ajax call?

79 views
Skip to first unread message

Paul Bergstrom

unread,
May 31, 2013, 3:44:23 PM5/31/13
to rubyonra...@googlegroups.com
I'm able to get json data back after an ajax call and into a div. But
how do I get it into html, styled format?

How about getting it to a partial? How do I do that in coffeescript?

--
Posted via http://www.ruby-forum.com/.

Benjamin Iandavid Rodriguez

unread,
May 31, 2013, 3:47:53 PM5/31/13
to rubyonra...@googlegroups.com
For what you say.

After you get the JSON response the partial is already processed so you just need to update the correct div with the correct info.

Use jQuery's append or html properties to update your divs.


2013/5/31 Paul Bergstrom <li...@ruby-forum.com>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/27f55d9596c7977ad612f3433528d425%40ruby-forum.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.



Paul Bergstrom

unread,
May 31, 2013, 4:14:28 PM5/31/13
to rubyonra...@googlegroups.com
Benjamin Iandavid Rodriguez wrote in post #1110828:
> For what you say.
>
> After you get the JSON response the partial is already processed so you
> just need to update the correct div with the correct info.
>
> Use jQuery's append or html properties to update your divs.
>
>
> 2013/5/31 Paul Bergstrom <li...@ruby-forum.com>

I haven't loaded the partial from start. Sorry but I don't know how to
update the div.

Paul Bergstrom

unread,
May 31, 2013, 4:57:53 PM5/31/13
to rubyonra...@googlegroups.com
I get an array back in json. That is loaded but without styling.

Fernando Jesus

unread,
Jun 6, 2013, 3:13:20 PM6/6/13
to rubyonra...@googlegroups.com
Have u solve your problem? i have the same issue U_U

Paul Bergstrom

unread,
Jun 8, 2013, 6:22:24 PM6/8/13
to rubyonra...@googlegroups.com
Fernando Jesus wrote in post #1111571:
> Have u solve your problem? i have the same issue U_U but without
> coffeeScript

Sorry to say, but no I didn't. Still looking.

Fernando Jesus

unread,
Jun 10, 2013, 1:26:21 PM6/10/13
to rubyonra...@googlegroups.com
Ok i found the solution:
http://stackoverflow.com/questions/7195473/rails-3-why-is-my-postshow-view-showing-all-of-its-comments-database-data-in


The problem is in the view perhaps you have =


it's the = in the @comments.each tag. It is returning the result of
each, which is the whole array.

For example:

irb> [1,2].each {|i| puts i }
1
2
=> [1, 2]
So:

<%= @comments.each do |comment| %>
Should simply be:

<% @comments.each do |comment| %>


I hope that works for you.

John Davalos

unread,
Jun 10, 2013, 5:03:43 PM6/10/13
to rubyonra...@googlegroups.com
i'm not sure what you mean by styled. json usually looks like this {user:{name:'fred',age:65}}. what kind of styling did you want to apply to that?  i'm guessing, but it sounds like you're looking for html elements to be returned?

typically after the request happens you can just use jquery's .html() method to insert your json into the element:

$('.element').html(json-data-returned-from-server)  where .element is the class name used by the html tag you're trying to insert your json.  

json is just a string so it's will be hard to add styling other than a font size, and font color.




--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages