HELP

I have a couple questions.

  1. I have a couple of emails.They are separated between buy comma or space.How to find which one is correct? I was thinking using regular expression like this one :
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i

2)How to put valid email address to database ?

3)If some email address is not valid then i have to give a massage using client-side which email are not valid
I was thinking javascript.But how?I don't know to use rails and javascript

Before I respond, are you saying that in a single input you are gathering multiple email addresses?

yes.

Predictably how many?

theoretically unlimited

example picture

Working with incomplete information here…

Single input, multiple values. I do not understand why? There are so many resources available for you to permit users to enter multiple and distinct emails values.

The following is crude, but I think that it may be helpful…

Well as far as I know you can’t use

ActionView::Helpers::FormHelper : ActionView::Helpers::FormHelper email_field(object_name, method, options = {})

From the browser instance, you can introduce an onChange event on your multiple value email field with JQuery/JavaScript:

making a call to something like (just offered as psuedo code):

var my_failed_email_address = Array // outside of the function, maybe

function validEmail(multiple_email_element_by_id)

 var emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
 ///  Someone can probably suggest a better reg exp

  Use Jquery to split the multiple_email_element_by_id field value by your required delimiter(s) and put it into an array...

            var my_email_address = Array  // Use the above to populate the array
            For each element in resulting array
               if (!( emailRegex.test(increment value) ) )  
                   return true  // maybe just return the empty array
              else
                 my_failed_email_address.push(that element)  // Otherwise add new value to array
                return false  //  maybe just return pupulated array
            end
          end

If this returns false, then you have numerous options: you can inform the user of failed email address(es) with an alert, populate some html span/error associated with the email input with meaningful error message, or change the css on the email input…

Or you can use validation in the Controller or Model in a similar fashion

In the Controller, parse the multiple email field from params and write a method to test for validity of each. If failure turn to originating render In the model, make accessible your multiple_email field, and write call back to parse the field for validation. On failure, inform user at View level with if model.errors.any?

Liz

CORRECTION:

Working with incomplete information here…

Single input, multiple values. I do not understand why? There are so many resources available for you to permit users to enter multiple and distinct emails values.

The following is crude, but I think that it may be helpful…

Well as far as I know you can’t use

ActionView::Helpers::FormHelper : http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-email_field email_field(object_name, method, options = {})

From the browser instance, you can introduce an onChange event on your multiple value email field with JQuery/JavaScript:

making a call to something like (just offered as psuedo code):

var my_failed_email_address = Array // outside of the function, maybe

function validEmail(multiple_email_element_by_id) return_value = true; var emailRegex = /[1]+@a-zA-Z0-9?(?:.a-zA-Z0-9?)*$/; /// Someone can probably suggest a better reg exp

  Use Jquery to split the multiple_email_element_by_id field value by your required delimiter(s) and put it into an array...

            var my_email_address = Array  // Use the above to populate the array
            For each element in resulting array
               if (!( emailRegex.test(increment value) ) )  
                   return_value = true;
              else
                 my_failed_email_address.push(that element)  // Otherwise add new value to array
                  return_value = false
            end

return return_value


  1. a-zA-Z0-9.!#$%&'*+/=?^_`{|}~- ↩︎

I know it’s dam but i have been given task .

If is up to me it will be totally different.

How can i memorised valid email to my database ? Where should i write this code?I mean the file. And how to connect this to my html.haml page.

This is the most complex task for me

I am not sure what you are asking. Are you asking how you save data in the database and how to extract it from the database for display? If so then I assume you are a beginner in Rails and need first to understand the basic principles. To that end I think your best plan would be to work right through a good tutorial such as railstutorial.org (which is free to use online) which will show you the basics of Rails. You would very quickly get back the time spent doing that.

Apologies if I have misunderstood your question, in which case please explain in more detail exactly what you do not know how to do.

Colin

The picture is mock-up. I can’t put data in database.Only valid emails goes to database but but I’m putting all e-mails in the database (valid and not valid)

I know for that course.That’s how I have learned Rails. Can you find what chapter in book is about database?How to extract data? Maybe i’m doing something wrong

I know for that course.That's how I have learned Rails. Can you find what chapter in book is about database?How to extract data? Maybe i'm doing something wrong

Have you really worked right through the tutorial? Virtually every chapter involves reading and writing from the database.

Colin

I know.I’m just angry because i can’t figure out a solution

I know.I'm just angry because i can't figure out a solution

You know what?

Colin

sqllite3.Standard for Rails

Do you have it installed? Do you know how to access it?

I’m putting every email into database.Those who are valid and those who aren’t I can’t figure out the condition

Maybe i can’t access database . I will make an assumption that i can’t access database. I’m ready for any advise

I have no idea how to finished this task. I’m getting pissed with this assignment.

I'm putting every email into database.Those who are valid and those who aren't I can't figure out the condition

Maybe i can't access database . I will make an assumption that i can't access database. I'm ready for any advise

Are you getting an error when you save the record, or does it appear the save is not working? I am assuming that you have written some code that attempts to save.

Colin

Hi Stepa,

Have you generated active record model? What controller are you using and how does it look like?

In general, You have to send a put request to your controller and pass all data you want to save or you have (depending on behaviour you are trying to achieve). Then you will be using ActiveRecord to save the data.

Please let us know at what point you are stuck.

I think it’s time for rebooting.

I will watch M. Hartl tutorial again (8th time). On Wednesday morning i will start again but this time from scratch .