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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:38:15+00:00 2026-06-15T00:38:15+00:00

Description I have the following working code. View with list of links: <%= div_for

  • 0

Description

I have the following working code.

  • View with list of links:

      <%= div_for feed do %>
        <%= link_to feed.name, { :controller => 'Feeds', :action => "get_posts", :id => feed.id }, 
      :remote => true %>  
      <% end %>
    
  • Controller which works when user clicks the link:

      def get_posts
        @result = Feed.find(params[:id]).generate_html_table    
    
        respond_to do | format |  
          format.js {render :layout => false}  
        end
      end
    
  • Method which generates HTML:

      def generate_html_table
          r = "<table>"
    
          self.posts.order("published desc").each { |p|                   
              link = '<a href=' + p.link + '>' + p.title + '</a>'
              date = '  ' + p.published.to_s
    
              r += '<tr><td>' + link + '</td><td>' + date + '</td></tr>'
          }    
    
          r + '</table>'
      end
    
  • And get_posts.js.erb:

      $( "#in" ).html("<%= raw @result %>");
    

Users clicks the link, generate_html_table generates HTML code which inserted into #id div.

Question

I want to change generate_html_table with partials. How can I get it?

How did I try it

  • I have created file views/feeds/_posts.html.erb with:

      some static text
    
  • I have edit my get_posts.js.erb as:

      $( "#in" ).html("<%= escape_javascript(render :partial => 'posts' )%>");
    

But even now, with static text it doesn’t 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-06-15T00:38:17+00:00Added an answer on June 15, 2026 at 12:38 am

    It looks like you have view code in the controller, you should get rid of the generate_html_table method and leave that to the get_posts.js.erb, when you are putting code that belongs to a view so clearly you know you are going offtrack.

    The get_posts.js.erb you have in the second part of the question seems right, I don’t see a #in in your previous view code where that code would be inserted, have you checked calling the ajax URL directly to discard a problem in the ajax part? (like not having loaded the jquery-ujs or whatever unobtrusive javascript platform you are using). I also don’t see any code that is handling the remote, so the javascript that is returning from the call is probably not being used.

    My recommendation would be:

    • get rid of generate_html_table
    • leave the gathering of the posts you want to gather (self.posts.order("published desc")) in the controller, that does belong in the controller
    • add code to the asset of your page to handle the ajax:success callback of your button to insert the html in #in
    • don’t return javascript in your ajax call, rather return the HTML that you need to insert, let the client handle the javascript part
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that creates the meta-description. I'm getting a 0 as
I have the following query: SELECT o.id,o.name FROM object o WHERE ( o.description LIKE
Say I have the following chef role: name test description role for test run_list
I have the following XML code. You will notice the tag Description is repeated,
I have the following JSON String { name:Product, properties: { id: { type:number, description:Product
I have the following input XML: <root age=1> <description>some text</description> <section> <item name=a> <uuid>1</uuid>
Ok, firstly I have the following code working.. although my question is this; should
I have the following action method that builds a drop down list which is
I have the following code that I am working on for my college assignment.
I have following code. It works fine in firefox but is not working in

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.