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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:26:36+00:00 2026-05-22T15:26:36+00:00

I’m working on my first ‘real’ (as opposed to playing around) rails 3 project

  • 0

I’m working on my first ‘real’ (as opposed to playing around) rails 3 project after using rails 1&2 for the last four years. In the destroy action’s js block i want to do something typical: remove the div containing the deleted resource on the page.

I can’t decide whether it’s better to render out a destroy.js.erb file like so: (the resource in question is a ‘note’ and the method .dom_id just returns a string like “note_#{note.id}”.)

Approach A: render a js view file

#in controller
  format.js

#in views/notes/destroy.js.erb
$('#<%= @note.dom_id %>').remove();

This has the advantage of keeping the controller totally clean and standard.

Approach B: put the js in the controller:

#in controller
format.js { render :text => "$('##{@note.dom_id}').remove()" }

This has the advantage of enabling the person looking at the controller code to instantly see what’s going on, without going hunting for a view file with one line of code in it. On the other hand, it breaks MVC.

What do you think? Which is more ‘proper’, ‘standard’, etc? Is there a third (fourth, fifth) way that’s even better?

  • 1 1 Answer
  • 1 View
  • 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-22T15:26:37+00:00Added an answer on May 22, 2026 at 3:26 pm

    I would tend to follow Approach A, even though you may only have a few lines worth of code. The reason is that you may have a teammate that sees Approach B and decides that when you need to add more JavaScript to the render, doing it inline is the correct approach. Inlining JavaScript can (according to what I’ve read) be used for very simple one one-liners, but even then it’s not recommended.

    If you want to avoid having to look around for the proper JS view file, you can always render a specific file rather than following the “file –> controller action” naming convention. That way the exact js.erb file you’re using is clear in your controller.

    • 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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text

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.