Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 721551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:53:11+00:00 2026-05-14T05:53:11+00:00

I am implemeting a facebook application in rails using facebooker plugin, therefore it is

  • 0

I am implemeting a facebook application in rails using facebooker plugin, therefore it is very important to use this architecture if i want to update multiple DOM in my page.
if my code works in a regular rails application it would work in my facebook application.

i am trying to use ajax to let the user know that the comment was sent, and update the comments bloc.

migration:

class CreateComments < ActiveRecord::Migration
 def self.up
    create_table :comments do |t|
      t.string :body

      t.timestamps
    end
  end

  def self.down
    drop_table :comments
  end
end

controller:

class CommentsController < ApplicationController

  def index
    @comments=Comment.all
  end

 def create
@comment=Comment.create(params[:comment])

  if request.xhr?
      @comments=Comment.all
      render :json=>{:ids_to_update=>[:all_comments,:form_message],
               :all_comments=>render_to_string(:partial=>"comments" ),
               :form_message=>"Your comment has been added." }
  else
    redirect_to comments_url
  end
 end

end

view:

<script>
function update_count(str,message_id) {
len=str.length;
if (len < 200) {
  $(message_id).innerHTML="<span style='color: green'>"+
    (200-len)+" remaining</span>";
} else {
  $(message_id).innerHTML="<span style='color: red'>"+
    "Comment too long. Only 200 characters allowed.</span>";
}
}


function update_multiple(json) {
for( var i=0; i<json["ids_to_update"].length; i++ ) {
    id=json["ids_to_update"][i];
    $(id).innerHTML=json[id];
}
}

</script>

<div id="all_comments" >
 <%= render :partial=>"comments/comments" %>
</div>

Talk some trash: <br />
<% remote_form_for Comment.new,
  :url=>comments_url,
  :success=>"update_multiple(request)" do |f|%>
<%= f.text_area :body,
 :onchange=>"update_count(this.getValue(),'remaining');" ,
 :onkeyup=>"update_count(this.getValue(),'remaining');"
%> <br />
<%= f.submit 'Post'%>
<% end %>

<p id="remaining" >&nbsp;</p>
<p id="form_message" >&nbsp;</p>
<br><br>
<br>

if i try to do alert(json) in the first line of the update_multiple function , i got an [object Object].

if i try to do alert(json[“ids_to_update”][0]) in the first line of the update_multiple function , there is no dialog box displayed.

however the comment got saved but nothing is updated.

questions:

1.how can javascript and rails know that i am dealing with json objects?deos ROR sent it a object format or a text format?

2.how can i see what is the returned json?do i have to parse it?how?

2.how can i debug this problem?

3.how can i get it to work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:53:11+00:00Added an answer on May 14, 2026 at 5:53 am

    You have to parse the returned JSON in your javascript using a JSON parser.

    Here is the one I use: https://github.com/douglascrockford/JSON-js/blob/master/json2.js

    So upon success you’ll do something like:

    var stuff = json.parse(returnedJSON)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my rails web application I am implementing Facebook connectivity. I want that whenever
I have a textarea element in a Facebook application I want to limit, visually,
I am implementing a facebook connect based application, and when I use $facebook->require_login() I
I have to integrate the Facebook social plugins into a JSF application. This recommends
I seem to be missing something very important in implementing Facebook like buttons to
I am implementing a Facebook application and using AJAX/JSON . However the JSON structures
I'm having trouble implementing this step: Given I am logged in as a Facebook
I am using xqj api for implemeting XQuery in java, the following is a
I am implementing facebook registration in my Yii site.. I setup application. For registration,
I use JSON for implementing Facebook in an app and I'm just making my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.