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

  • Home
  • SEARCH
  • 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 7406585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:34:50+00:00 2026-05-29T05:34:50+00:00

I am using Rails 3.1, it seems that I could not use Ruby script

  • 0

I am using Rails 3.1, it seems that I could not use Ruby script after a CoffeeScript statement in my create_error.js.coffee view file for the AJAX response.

If I do it like this it will work:

<% if @attached_image.errors.any? %>
  alert 'something is wrong'
<% end %>

but if it is like the following, with a <% %> after the CoffeeScript statement,

errors_block = '<div id="errors_block"></div>'
<% if @attached_image.errors.any? %>
  something..
<% end %>

I will alway get an exception of ActionView::Template::Error (Parse error on line 6: Unexpected 'INDENT') on the if line. I’ve tried several samples, everytime it happens when a ruby <% %> comes after a coffeescript statement.

Why is that?

  • 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-29T05:34:51+00:00Added an answer on May 29, 2026 at 5:34 am

    Sounds like you’re running into indentation issues in your post-ERB CoffeeScript. Given this:

    errors_block = '<div id="errors_block"></div>'
    <% if @attached_image.errors.any? %>
      something...
    <% end %>
    

    The output will look like this when the if condition is true:

    errors_block = '<div id="errors_block"></div>'
    
      something...
    

    and that indentation starts a new block that doesn’t make sense in that context; hence the “Unexpected ‘INDENT'” error from the CoffeeScript compiler. You can see this in action in this snippet on coffeescript.org.

    CoffeeScript is very sensitive to indentation so mixing ERB and CoffeeScript like that isn’t a good idea. You’d be better off putting @attached_image.errors into a CoffeeScript variable and then doing the logic in CoffeeScript, something more like this (untested code):

    errors = <%= @attached_image.errors.to_a.to_json.html_safe %>
    errors_block = '<div id="errors_block"></div>'
    if errors.length > 0
      something...
    

    The JSON version of the errors array should be valid CoffeeScript so errors will be a CoffeeScript array. The to_a is there in case errors returns nil, I’m not sure off the top of my head if errors.nil? is possible but a little extra paranoia never hurt anyone.

    You could also do this:

    errors_block = '<div id="errors_block"></div>'
    <% if @attached_image.errors.any? %>
    something..
    <% end %>
    

    but that’s harder to read and you will forget. You’re better off using ERB to generate CoffeeScript data and letting CoffeeScript handle the logic.

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

Sidebar

Related Questions

Using Rails v2.1, lets say you have an action for a controller that is
I'm using rails 2.3.5 with i18n. I's there a way to find all not
Using Rails, is there a reason why I should store attachments (could be a
I've developed a web interface for a legacy (vendor) database using Ruby on Rails.
I am considering ditching Ruby on Rails for my web-development pet-project and using a
I am following a Ruby on Rails tutorial in a book that uses Acts
im using rails 2.3 and ruby 1.8.7, I have version .0.1.6 of crack vendored
I am working on creating a adserver using rails 3.1 and ruby 1.9.2. In
I am working on a very large Rails application. We initially did not use
When using Rails date_select with :prompt => true I see some very strange behavior

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.