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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:02:44+00:00 2026-06-03T21:02:44+00:00

Is there a way for me to call ruby on rails functions from within

  • 0

Is there a way for me to call ruby on rails functions from within javascript?
For instance I have a partial => _micropost_form.html.erb and I want it to appear in a separate div when a button is clicked. I figured the best way to do that would be to use javascript. Currently I have:

document.getElementById("micropost").innerHTML= 

So I’m pretty lost. I feel like this should be a pretty simple problem to work out though. Thanks!

EDIT:

So I have a link in my _header file:

<li>Add Content</li>

As well as a div:

<div id="popout"></div>

In my content controller I have a method:

def add_content
@content = Content.new
respond_to do |format|
format.html
format.js
end

As well as the file (located in views/contents) add_content.js.erb (_content_form is an html.erb file located in shared)

$('#popout').replaceWith("<%= escape_javascript render
            (:file => 'shared/_content_form') %>");

I know the call I’m supposed to make in <li>Add Content</li> involves link_to however, I have yet to be able to get it to work correctly. The output to the console usually looks like a page refresh. Any help would be greatly appreciated!

  • 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-06-03T21:02:46+00:00Added an answer on June 3, 2026 at 9:02 pm

    In addition to the answer by ismaelga, I would like to add that if you have static HTML content in _micropost_form.html.erb then there’s no reason why that should be a erb file or a partial. Having that content within a hidden div and then toggling that based on the button click would be a good solution.

    If, however, you have dynamic content in that file then your best bet is to use AJAX. Some of the links provided by Felix Cling in the comments are a good starting point. I find myself using the following line of code in the .js.erb file quite a bit though to achieve what you want to:

    $('#micropost').replaceWith("<%= escape_javascript render(:file => 'micropost_form.html.erb') %>");
    

    Or, you could use the jquery append instead of replaceWith.

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

Sidebar

Related Questions

Is there a way to call functions within a class upon instantiation of that
I am wondering: is there a way to call a method from within itself
Is there any way to call an action script function from an anchor which
is there any way to call servlet or make a gwt-rpc call from gwt
Is there a way to call multiple methods from backing bean in JSF? I
Is it possible to call a ruby method inside javascript? One way of implementing
Is there a way in the Ruby On Rails Routing framework to make a
In Ruby on Rails, is there a standard way of restricting certain methods in
Is there a way to call send / recv passing in a vector ?
is there a way to call java me application out of Symbian's C++ app?

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.