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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:37:40+00:00 2026-05-27T15:37:40+00:00

I’ve become a bit confused about the idea of rendering a template due to

  • 0

I’ve become a bit confused about the idea of “rendering” a “template” due to the way an author speaks about it in a book I’m reading.

My original understanding of “rendering a template” was that it meant that Rails is providing the content that is viewed on the screen/presented to the viewer (in the way that a partial is rendered) but the book I’m reading seems to be using the concept of “rendering a template” to also mean something else. Let me explain in context

This book (rails 3 in action) sets up a page layout using the conventional layouts/application.html.erb file, and then it “yields” to different view pages, such as views/tickets/show.html.erb which adds more content to the screen. that’s all straightforward..

Within this view views/tickets/show.html.erb, there is a rendering of a partial (which is also a straightforward concept).

<div id='tags'><%= render @ticket.tags %></div>

Now within this partial there is, using ajax, a call to a “remove” method in the “tags_controller.rb” which is designed to allow authorized users to remove a “tag” from a “ticket” in our mock project management application.

<% if can?(:tag, @ticket.project) || current_user.admin? %>
    <%= link_to "x", remove_ticket_tag_path(@ticket, tag),
      :remote => true,
      :method => :delete,
      :html => { :id => "delete-#{tag.name.parameterize}" } %>
  <% end %>

Now here is the “remove” action in the tags controller (which disassociates the tag from the ticket in the database)…

def remove
    @ticket = Ticket.find(params[:ticket_id])
    if can?(:tag, @ticket.project) || current_user.admin?
      @tag = Tag.find(params[:id])
      @ticket.tags -= [@tag]
      @ticket.save
    end
  end
end

At the end of this remove action, the author originally included render :nothing => true , but then he revised the action because, as he says, “you’re going to get it to render a template.” Here’s where I get confused

The template that he gets this action to render is “remove.js.erb”, which only has one line of jquery inside it, whose purpose is to remove the “tag” from the page (i.e. the tag that the user sees on the screen) now that it has been disassociated from the ticket in the database.

$('#tag-<%= @tag.name.parameterize %>').remove();

When I read “rendering a template” I expect the application to be inserting content into the page, but the template rendered by the “remove” action in the controller only calls a jquery function that removes one element from the page.

If a “template” is “rendered”, I’m expecting another template to be removed (in order to make room for the new template), or I’m expecting content to be “rendered” in the way that a partial is rendered. Can you clarify what is actually happening when a “template” is “rendered” in the situation with the jquery in this question? Is it actually putting a new page in front of the user (I expected some sort of physical page to be rendered)

  • 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-27T15:37:40+00:00Added an answer on May 27, 2026 at 3:37 pm

    You’re nearly there! Rendering a template is indeed always about producing content, but for a slightly wider description of content. It could be a chunk of html, for example an ajax call to get new items might produce some html describing the new items, but it doesn’t have to be.

    A template might produce javascript as it does in your second example. Personally I am trying to avoid this and instead pass JSON back to the client and let the client side js perform the required work.

    Another type of rendering you might perform is to produce some JSON. APIs will often do this, but you might also do this on a normal page. For example rather than rendering some javascript to delete tag x you might render the json

    { to_delete: "tag-123"}
    

    and then have your jQuery success callback use that payload to know which element to remove from the DOM, by having this in your application.js file

    $('a.delete_tag').live('ajax:success', function(data){
      var selector = '#' + data.to_delete;
      $(selector).remove()
    }
    

    (Assuming that your delete links had the class ‘delete_tag’)
    Rendering JSON like this isn’t really a template at all, since you’d usually do this via

    render :json => {:to_delete => "tag-#{@tag.name.parameterize}"}
    

    although I suppose you could use an erb template for this (I can’t imagine why though).

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.