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

  • SEARCH
  • Home
  • 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 7550363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:11:35+00:00 2026-05-30T10:11:35+00:00

I am appending code to a div block from a partial using unobtrusive javascript.

  • 0

I am appending code to a div block from a partial using unobtrusive javascript. Inside my views there are two folders called videos and posts. In the the video folder is a show.html.erb file. In this show.html.erb file there’s a form to allow a user to create a post. The form attribute remote is set to true and I want the post that gets submitted by the form to be loaded onto the page (the same show.html.erb page) without having to refresh (AJAX functionality). When the form is submitted it is sent to the create method of the posts controller. In this method there’s a

format.js

that calls views > posts > create.js.erb.
The code I have written for this file so far is:

$('#comments').append('<%=escape_javascript(render(:partial => 'posts'))%>');

comments is the div id for a block in the show.html.erb file. The partial ‘posts’ is inside the posts folder (views > posts > _posts). Right now this is not working properly and I believe its because the create.js.erb file is in a separate folder from the file whose div id its trying to reference. How do I get the javascript code from the posts folder to reference the div block inside the video show file? Thanks.

  • 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-30T10:11:36+00:00Added an answer on May 30, 2026 at 10:11 am

    Being relatively new to rails and even newer to jquery I had an issue in identifying my problem. I thought that because my jquery code was in a separate folder from the div I wanted to reference that the code I had above wouldn’t work properly. The answer (as I found out) is that as long as the div and the jquery are in the same DOM the reference works fine. I had a bug somewhere else in my code that was preventing the AJAX request from functioning normally. After fixing that my jquery code works as intended. Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm loading new HTML/JS content using ajax and appending it to some div block
In the above code, I am appending a javascript onclick method to the image
I am creating a LI and appending it to the UL using JQUERY code.
I have a blank div called content. Links are later added to content using
First of all, I'm using the following code to generate a form via JavaScript
I followed all of the instructions so far from: http://code.google.com/p/appengine-jruby/wiki/RunningRails and http://gist.github.com/268192 Currently, I'm
When appending to a file using Windows batch commands, how to append immediately after
I am using WAMP. I want to take background image URL from my database
I want to append a div tag generated by jQuery dynamically with a javascript
I'm creating <div> 's and appending them to a literal's text property. I have

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.