Validates is exists

Discussion in 'Ruby' started by Jose tomas R., Jan 3, 2011.

  1. Event has_and_belongs_to_many :users
    User has_and_belongs_to_many :events

    Im trying to verify that user doesnt signup more than one time


    def signup
    @event = Event.find(params[:id])
    @user = current_user
    respond_to do |format|
    if @event.users.find(@user) != @user.id
    @user.events << @event
    format.html { redirect_to(@event, :notice => 'You where
    successfully Signed Up.') }
    format.xml { head :eek:k }
    else
    format.html { redirect_to(@event, :notice => 'You where already
    Signed Up.') }
    format.xml { head :eek:k }
    end
    end
    end

    but i think that's no ok, i get this message, when the user havent
    signed up:

    Couldn't find User with ID=2 [WHERE ("events_users".event_id = 7 )]

    --
    Posted via http://www.ruby-forum.com/.
    Jose tomas R., Jan 3, 2011
    #1
    1. Advertising

  2. On Mon, Jan 3, 2011 at 7:14 PM, Jose tomas R. <> wrote:
    > Event has_and_belongs_to_many :users
    > User =A0has_and_belongs_to_many :events
    >
    > Im trying to verify that user doesnt signup more than one time


    1) Rails questions get better service one link over in the Rails forum. :)

    2) Given that there's dozens of free email services out there and
    making up a fake name is trivial, how do you suppose to stop the user
    signing up multiple times, anyway? Short of using credit card numbers,
    and I doubt you can verify those with the issuers, anyway (PCI
    compliance is not something you want to burden yourself with).

    --=20
    Phillip Gawlowski

    Though the folk I have met,
    (Ah, how soon!) they forget
    When I've moved on to some other place,
    There may be one or two,
    When I've played and passed through,
    Who'll remember my song or my face.
    Phillip Gawlowski, Jan 3, 2011
    #2
    1. Advertising

  3. Jose tomas R.

    Josh Cheek Guest

    [Note: parts of this message were removed to make it a legal post.]

    On Mon, Jan 3, 2011 at 12:38 PM, Phillip Gawlowski <
    > wrote:

    > 2) Given that there's dozens of free email services out there and
    > making up a fake name is trivial, how do you suppose to stop the user
    > signing up multiple times, anyway? Short of using credit card numbers,
    > and I doubt you can verify those with the issuers, anyway (PCI
    > compliance is not something you want to burden yourself with).
    >
    >

    Of course, if the site lags a little bit, and they impatiently click the
    button five times, you don't want to displace four other guests.
    Josh Cheek, Jan 3, 2011
    #3
  4. On Mon, Jan 3, 2011 at 8:11 PM, Josh Cheek <> wrote:
    >
    > Of course, if the site lags a little bit, and they impatiently click the
    > button five times, you don't want to displace four other guests.


    It's a reasonable assumption that a person registering for an event 5
    times in quick succession meant to only go once. It's also a nice UX
    trick to use JavaScript to grey out the form's submit button once it
    has been clicked. Or you go to a placeholder site while you process
    the data. Or send the data off to a worker threat, and redirect the
    user to another page, telling them their request is being processed
    and will show up soon.

    --
    Phillip Gawlowski

    Though the folk I have met,
    (Ah, how soon!) they forget
    When I've moved on to some other place,
    There may be one or two,
    When I've played and passed through,
    Who'll remember my song or my face.
    Phillip Gawlowski, Jan 3, 2011
    #4
  5. Jose tomas R. wrote in post #972073:
    > Event has_and_belongs_to_many :users
    > User has_and_belongs_to_many :events
    >
    > Im trying to verify that user doesnt signup more than one time

    ...
    > if @event.users.find(@user) != @user.id


    Foo.find(x) looks for a record with id X, and will raise an exception if
    it doesn't exist, as you already discovered.

    Completely untested, but you could try some variation of

    if @event.users.find_by_id(@user.id)

    if @event.users.where:)id => @user.id).count > 0

    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, Jan 4, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Buddy Ackerman
    Replies:
    2
    Views:
    472
  2. Richard

    Now it validates!

    Richard, Jan 13, 2004, in forum: HTML
    Replies:
    11
    Views:
    715
  3. Titus A Ducksass - AKA broken-record
    Replies:
    6
    Views:
    650
    Titus A Ducksass - AKA broken-record
    Nov 15, 2004
  4. Lyle Ladeira

    validates characters

    Lyle Ladeira, Jul 28, 2004, in forum: C++
    Replies:
    6
    Views:
    307
    Ioannis Vranos
    Jul 30, 2004
  5. Jon   Paal

    license file never validates as true

    Jon Paal, Aug 30, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    302
    Jon Paal
    Aug 30, 2006
Loading...

Share This Page