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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:28:37+00:00 2026-06-18T02:28:37+00:00

I am trying to do validation but didnot find the right way while uploading

  • 0

I am trying to do validation but didnot find the right way while uploading the excel

Code for view

<%= form_for :dump, :url=>  import_csv_index_path, :html => { :multipart => true } do |f| %>
<% if (-----).errors.any? %>
<div id="error_explanation">
 <%= pluralize((----).errors.count, "error") %> prohibited this link from being saved:

<% (---).errors.full_messages.each do |msg| %>
<li><%= msg %></li>
</div>

<% end %>

    <%= f.label :'Select an Excel File:'  %>
    <%= f.file_field :file %>
    <i href="#" id="blob_1" class="icon-info-sign" rel="popover" style="margin-top: 300px"></i><br/>

    <%= submit_tag 'Submit' ,:id => 'submit',:class =>"btn btn-primary"%><br/><br/>

<% end -%>

Code for model:

class Person < ActiveRecord::Base

 attr_accessible :date, :email, :name, :avatar ,:template_id

 validates_presence_of :email,:message => 'Email is compulsory' 

end

What do i write at place of (—–)

Thank you

  • 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-18T02:28:38+00:00Added an answer on June 18, 2026 at 2:28 am

    I have done with the other approach so discuss here,

    Code for controller:

     def import
    
       @error = []
       @error = Person.import(params[:dump][:file])
     redirect_to people_path, notice: "Employees imported.",:flash => { :error =>   "Employees(   Email : invalid/blank) are not saved : #{@error.join("  , ")}" }
    end
    

    In model:

    def self.import(file)

     spreadsheet = open_spreadsheet(file)
      @err = []
      @alt = []
    
      header = spreadsheet.row(1)
        (2..spreadsheet.last_row).each do |i|
        row = Hash[[header, spreadsheet.row(i)].transpose]
        @person = Person.find_by_id(row["id"]) ||Person.new
    
    
    
     @person.name = row["Name"].to_s
        @person.date = row["Date"]
        @person.email = row["Email"]
    
    
    
      if @person.save
    
         else
            @err << {:name => row["Name"].to_s,:error => @person.errors.messages}
         end
    
        end
        @err.each do |t|
    
    
    
       @alt.push(t[:name])
    
    
        end
    
      return @alt
    
    end
    

    and call that as flash message…and working fine now.

    Thanks

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

Sidebar

Related Questions

I am trying to find a way to query a RNG schema while avoiding
i am trying to modify one js file validation rule but unable to do
I trying to update a model on a callback but the validation is causing
I'm trying to set form validation with cyrillic alphabet but I get We're sorry,
I am trying to use same validation function for all my controls. But I
Im trying to create a simple input box with form validation, but im not
Hey in trying to submit my app to iTunes. It passes the validation, but
I'm trying to write my own Custom Validation attribute but I'm having some problems.
I'm trying to use bootstrap with the jquery validation plugin but when I try
I am trying to write an active record validation that allows any string 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.