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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:58:33+00:00 2026-05-19T23:58:33+00:00

I am running Ruby on Rails 3 and Prototype and I would like to

  • 0

I am running Ruby on Rails 3 and Prototype and I would like to check the file extension on selecting a file for file_field, so I can show an error if it is not one of those that are permitted (in my case only .doc and .pdf are permitted extensions).

At this time in my view file I obseve the file_field in this way:

page.event.observe('file_field_id', 'change') do |element|
  # Here I would like to put some code in order to check the file extension
  # If the file extension isn't '.doc' or '.pdf' I would like to set and show an error text in the 'error_id'
  # I know using 'element[:error_id].show' I can show the error, but...
  #   1. how to set the error value?
  #   2. how to check the file extension?
end

Now I need to check if, after selecting a file, the string in the file_field have the exention .docor .pdf and if no, set a value for the error_id and show it.

How I can do that?


UPDATE: I need that using the Protoype framework. Is it possible?

  • 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-19T23:58:34+00:00Added an answer on May 19, 2026 at 11:58 pm

    In JS, by using regular expression you can get file extension.

    var extens=(/[.]/.exec(myfile)) ? /[^.]+$/.exec(myfile) : undefined;
    

    Here myfileis the address or the path of the file. This simply takes the part of the string after “.” . Then you can place some control checks with if. Something like :

    if(extens=="doc" || extens=="pdf")
    {
           //your method goes here
    }
    else
    {
           error_id= ........
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking at ways to deploy a Ruby on Rails app (running on JRuby)
I am running OS X 10.5, Ruby 1.8.6, Rails 2.1, sqlite3-ruby 1.2.2 and I
I'm running ruby on rails v2.2.2 and when I run rake gems I get
I have ruby on rails installed on my Desktop running ruby 1.8.7 and rails
Okay I have an extensive ruby application running behind Ruby on Rails right now.
I am setting up an Apache2 webserver running multiple Ruby on Rails web applications
I get this error when trying ruby script/console Rails requires RubyGems >= . Please
I tried starting my Rails application but got this error message from Passenger: Ruby
I am running Ruby and MySQL on a Windows box. I have some Ruby
I am running ruby script/generate scaffold or ruby script/generate model and I know the

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.