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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:56:03+00:00 2026-06-16T03:56:03+00:00

I made an application that has a project model. The model has some information

  • 0

I made an application that has a project model. The model has some information stored in it, and a user can add comments to the project (using the comment model). In the show view of a project I want the user to be able to switch between an “info” partial (containing the project information, and a “comment” partial (containing the comments wrote on the project). I want to do this using AJAX. So I will have two buttons: Information & Comments.

Now I know how to render a partial based on a “remote link”, but I’ll also have to find out which link was clicked. So far I can render one partial when one link is clicked like so:

// In show.html.haml

= link_to("Information", :project, :id => "link_one", :remote => true)
= link_to("Comments", :project, :id => "link_two", :remote => true)

#partial_window


// In show.js.haml
$("#partial_window").html("#{j(render("comments"))}")

Now this renders the _comment.html.haml partial when I click on one of the links. What I need to know is how to check which link was clicked, and then render the appropriate partial: _info.html.haml or _comments.html.haml.

Thanks in advance for your help!

  • 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-16T03:56:04+00:00Added an answer on June 16, 2026 at 3:56 am

    Something like this should work. We are going to use nested routes. Check out ryan’s screencast (a little old, but it gets the point across) or this more updated version about nested forms (uses the same principles). You’ll have to pay for the updated version, but I find my RailsCast subscription to be more than worth the $9/month. Also, here are the docs for examples.

    config/routes.rb

    resources :projects do
      resources :comments
    end
    

    comments_controller.rb

    class CommentsController < ApplicationController
      def index
        project = Project.find params[:project_id]
        @comments = project.comments
        respond_to do |format|
         format.html #responds with default html file
         format.js #this will be the javascript file we respond with
        end
      end
    end
    

    views/comments/index.js.erb

    $('#holderDiv').empty().append('<ul> <%= j render @comments %> </li>')
    

    This uses a nifty thing of rails that looks for a comment partial and renders it for each comment in @comments. The j helper escapes javascript and pretty much inserts the rendered partial into the append function.

    views/comments/_comment.html.erb

     <li> <%= @comment.description %> </li>
    

    So we’ve now cleared the #holdingDiv and inserted our comments. For information, maybe something like this:

    projects_controller.rb

    class ProjectsController < ApplicationController
      def index
        @project = Project.find params[:id]
        respond_to do |format|
          format.html
          format.js
        end
      end
    end
    

    views/project/index.js.erb

     $('#holderDiv').empty().append('<%= j render 'information', information: @project.information %>')
    

    views/project/_information.html.erb

    <h2>
      <%= information.title %>
    </h2>
    <p>
      <%= infomration.details %>
    </p>
    

    Then, your remote links would be something like:

    = link_to("Information", @project, :remote => true)
    = link_to("Comments", project_comments_url(@project), :remote => true)
    

    I had to make some assumptions about what your data structures were. Let me know where I’ve confused you.

    Also, I am sure I have some typos, sorry for that. I did not test this, just went off the top of my head.

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

Sidebar

Related Questions

I have an application that needs to determine whether a user has made a
I have a Setup Project that I made using Visual Studio 2010. The application
I have project model that has many tasks. Both project and tasks can have
I have made an application that gives the user the option to open up
I have made an application in android that lets the user compress and decompress
I've made an application that takes tagged versions of a project from an hg
there is a user control on my Application.(App1) now I have made some changes
I made a simple silverlight web application that just has one button filling up
I have an Exception Handling project in my application that can be called from
I made an application that passes trough an XML file and extracts the entries

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.