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 6921939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:20:28+00:00 2026-05-27T10:20:28+00:00

I’m new to web development so bear that in mind. I’m creating my first

  • 0

I’m new to web development so bear that in mind.

I’m creating my first app using Rails 3.0.10

I have a micropost form that I’m trying to implement AJAX into.

I have set up the controller correctly(I believe) and have added :remote => true to the micropost form.

Microposts Controller

def create
      @user = User.find(current_user.id)
      @micropost = current_user.microposts.build(params[:micropost])
      if @micropost.save
        flash[:success] = "Created micropost"
        respond_to do |format|
        format.html { redirect_to @user }
        format.js
      end
      else
        render 'users/show'
      end
    end

The problem is in the create.js.erb file, in views/microposts

As a test, if I put

$("#microposts").html("<p>Hello world!</p>")

it works as expected.

Even if I embed ruby code into it with an instance variable, that works too.

But, if I put

$("#microposts").html("<%= render @microposts %> ")

it does nothing.

In fact, as soon as I try any rails method, it does nothing.

These are my javascript files that are included:

/javascripts/jquery.js
/javascripts/jquery_ujs.js
/javascripts/jquery.min.js
/javascripts/application.js

Any help would be greatly appreciated, I have been stumped for little while now.

  • 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-27T10:20:29+00:00Added an answer on May 27, 2026 at 10:20 am

    You’re not loading @microposts (the collection) in the create action.

    So, you need to either need to set it via something like:

    @microposts = current_user.microposts
    

    But there’s really no need to do another DB call. I’d recommend just appending (or prepending) your #microposts element with the new item. Something like:

    $("#microposts").prepend("<%= escape_javascript(render '_micrpost_item') %>");
    

    And that partial should be able to use the @micropost object from the create action.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker

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.