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?

https://lh3.googleusercontent.com/-m_BZD9awBgM/VZrcgA0wDAI/AAAAAAAAAAs/trS5JfhMeQ8/s1600/trial_task.jpg
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 :

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?)$/;
/// 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:

On Monday, July 6, 2015 at 4:43:45 PM UTC-4, Elizabeth McGurty wrote:

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

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

On 6 July 2015 at 22:41, StepaAr [email protected]
wrote:

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)

Regarding:

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.

Seems to me that you are working with an existing application, or is the
image you presented some mock-up? If it is an existing application, is
the
application written in Rails? Before I go into more detail, please
provide
me (us) with your answers.
Thanks,

On 7 July 2015 at 20:35, StepaAr [email protected]
wrote:

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 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

On 8 July 2015 at 06:56, StepaAr [email protected]
wrote:

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

You know what?

Colin

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

What database are you using?

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.

On 9 July 2015 at 20:07, StepaAr [email protected]
wrote:

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