HELP

146 views
Skip to first unread message

StepaAr

unread,
Jul 6, 2015, 11:58:39 AM7/6/15
to rubyonra...@googlegroups.com
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

Elizabeth McGurty

unread,
Jul 6, 2015, 1:46:57 PM7/6/15
to rubyonra...@googlegroups.com
Before I respond, are you saying that in a single input you are gathering multiple email addresses?

StepaAr

unread,
Jul 6, 2015, 3:04:57 PM7/6/15
to rubyonra...@googlegroups.com
yes.

Elizabeth McGurty

unread,
Jul 6, 2015, 3:46:22 PM7/6/15
to rubyonra...@googlegroups.com
Predictably how many?

StepaAr

unread,
Jul 6, 2015, 3:52:49 PM7/6/15
to rubyonra...@googlegroups.com

theoretically unlimited

example picture

Elizabeth McGurty

unread,
Jul 6, 2015, 4:43:45 PM7/6/15
to rubyonra...@googlegroups.com
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)

     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

Elizabeth McGurty

unread,
Jul 6, 2015, 5:00:27 PM7/6/15
to rubyonra...@googlegroups.com
CORRECTION:


On Monday, July 6, 2015 at 4:43:45 PM UTC-4, Elizabeth McGurty wrote:
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 = /^[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_value = true;

                  else
                     my_failed_email_address.push(that element)  // Otherwise add new value to array
                      return_value = false
                end
                  return return_value  

StepaAr

unread,
Jul 6, 2015, 5:41:21 PM7/6/15
to rubyonra...@googlegroups.com
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

Colin Law

unread,
Jul 7, 2015, 3:56:52 AM7/7/15
to rubyonra...@googlegroups.com
On 6 July 2015 at 22:41, StepaAr <ser.arseni...@gmail.com> wrote:
>
> 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
Message has been deleted

StepaAr

unread,
Jul 7, 2015, 3:32:45 PM7/7/15
to rubyonra...@googlegroups.com
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)



On Tuesday, July 7, 2015 at 4:35:15 PM UTC+2, Elizabeth McGurty wrote:
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,

StepaAr

unread,
Jul 7, 2015, 3:35:24 PM7/7/15
to rubyonra...@googlegroups.com
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

Colin Law

unread,
Jul 7, 2015, 3:57:24 PM7/7/15
to rubyonra...@googlegroups.com
On 7 July 2015 at 20:35, StepaAr <ser.arseni...@gmail.com> 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

>
>
>
> On Tuesday, July 7, 2015 at 9:56:52 AM UTC+2, Colin Law wrote:
>>
>> On 6 July 2015 at 22:41, StepaAr <ser.arseni...@gmail.com> wrote:
>> >
>> > 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
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/3676154d-efa1-4c52-8daa-5f8b77329afe%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

StepaAr

unread,
Jul 8, 2015, 1:56:25 AM7/8/15
to rubyonra...@googlegroups.com
I know.I'm just angry because i can't figure out a solution

Colin Law

unread,
Jul 8, 2015, 3:51:39 AM7/8/15
to rubyonra...@googlegroups.com
On 8 July 2015 at 06:56, StepaAr <ser.arseni...@gmail.com> wrote:
> I know.I'm just angry because i can't figure out a solution

You know what?
> https://groups.google.com/d/msgid/rubyonrails-talk/54408c31-994a-441e-998f-bb0acefa2aac%40googlegroups.com.
Message has been deleted

StepaAr

unread,
Jul 9, 2015, 9:33:13 AM7/9/15
to rubyonra...@googlegroups.com
sqllite3.Standard for Rails





On Wednesday, July 8, 2015 at 1:58:34 PM UTC+2, Elizabeth McGurty wrote:
What database are you using?

Elizabeth McGurty

unread,
Jul 9, 2015, 9:46:00 AM7/9/15
to rubyonra...@googlegroups.com
Do you have it installed?  Do you know how to access it?

On Thursday, July 9, 2015 at 9:33:13 AM UTC-4, StepaAr wrote:
sqllite3.Standard for Rails

StepaAr

unread,
Jul 9, 2015, 3:07:59 PM7/9/15
to rubyonra...@googlegroups.com
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.

Colin Law

unread,
Jul 9, 2015, 3:22:57 PM7/9/15
to rubyonra...@googlegroups.com
On 9 July 2015 at 20:07, StepaAr <ser.arseni...@gmail.com> 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

>
>
> I have no idea how to finished this task.
> I'm getting pissed with this assignment.
>
>
>
>
> On Thursday, July 9, 2015 at 3:46:00 PM UTC+2, Elizabeth McGurty wrote:
>>
>> Do you have it installed? Do you know how to access it?
>>
>> On Thursday, July 9, 2015 at 9:33:13 AM UTC-4, StepaAr wrote:
>>>
>>> sqllite3.Standard for Rails
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0ddc1187-07e4-4e4f-8686-37ad8674b030%40googlegroups.com.

Taras Matsyk

unread,
Jul 12, 2015, 5:46:03 AM7/12/15
to rubyonra...@googlegroups.com
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.

--
Posted via http://www.ruby-forum.com/.

StepaAr

unread,
Jul 13, 2015, 4:28:40 PM7/13/15
to rubyonra...@googlegroups.com
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 .

Colin Law

unread,
Jul 13, 2015, 4:54:20 PM7/13/15
to rubyonra...@googlegroups.com
On 13 July 2015 at 21:28, StepaAr <ser.arseni...@gmail.com> wrote:
> I think it's time for rebooting.
>
> I will watch M. Hartl tutorial again (8th time).

Don't just watch it, work right through it, entering all the code,
getting it working and doing the exercises.

Colin

StepaAr

unread,
Jul 13, 2015, 5:47:24 PM7/13/15
to rubyonra...@googlegroups.com

Of course.It will be 8th time to code he's twitter again

The problem for me is simple.
I have this emails:

jo...@gmail.com, al...@gmal89.com, ste...@yahoo.com, mi...@yahoo.com and the all have some message (example): like a flower

The second email is invalid and i have made that working typing in create controller condition for saving data
Like this:

def create
if @invations.save && @invitations.check_for_valid_emails
#bla bla


this provided that i cant save wrong emails but when i correct email like this:

jo...@gmail.com, al...@gmal.com, ste...@yahoo.com, mi...@yahoo.com

he doesn't save all emails but only first email (jo...@gmail.com) with message  like a flower  in database (i have check this by using index page i.e when i open index page
                                                                                                                                                         i can see only message for first email)

while i should seen for all my email saved massage.

  MY QUESTION IS:

How can i save for every (working) email (separated) in database with the  same message? Now i'm saving only for first email.

Conclude:
I have to save every valid email in database separated with message

This is layout (picture how it should look) is at the beginning of this replay

I need to finish this task by Thursday

Colin Law

unread,
Jul 14, 2015, 3:29:44 AM7/14/15
to rubyonra...@googlegroups.com
On 13 July 2015 at 22:47, StepaAr <ser.arseni...@gmail.com> wrote:
>
> Of course.It will be 8th time to code he's twitter again
>
> The problem for me is simple.
> I have this emails:
>
> jo...@gmail.com, al...@gmal89.com, ste...@yahoo.com, mi...@yahoo.com and the all have some message (example): like a flower
>
> The second email is invalid and i have made that working typing in create controller condition for saving data
> Like this:
>
> def create
> if @invations.save && @invitations.check_for_valid_emails
> #bla bla
>
>
> this provided that i cant save wrong emails but when i correct email like this:
>
> jo...@gmail.com, al...@gmal.com, ste...@yahoo.com, mi...@yahoo.com
>
> he doesn't save all emails but only first email (jo...@gmail.com) with message like a flower in database (i have check this by using index page i.e when i open index page

You say you have the emails shown, but have not said in what way you
'have' them. Are they encoded into a single string or in separate
fields from a form or what? If you look in log/development.log you
will see the parameters that are passed in to your action. Copy and
paste here the section from the log file that shows the create action.
Also you have not explained how you wish them saved. Are they in
separate records or somehow encoded into a single record?

In your create method you show it saving @invations then checking a
different variable @invitations. Always copy/paste code here rather
than re-typing otherwise we do not know whether the errors we see are
just typos in the email. You do not seem to have set @invitations to
any value, and also you are checking for valid emails only after you
save it. Is that correct? Normally data validity checks would be
done in validations so that the save only happens if the data are
valid.

Colin
Reply all
Reply to author
Forward
0 new messages