Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Validates is exists

Reply
Thread Tools

Validates is exists

 
 
Jose tomas R.
Guest
Posts: n/a
 
      01-03-2011
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 k }
else
format.html { redirect_to(@event, :notice => 'You where already
Signed Up.') }
format.xml { head 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/.

 
Reply With Quote
 
 
 
 
Phillip Gawlowski
Guest
Posts: n/a
 
      01-03-2011
On Mon, Jan 3, 2011 at 7:14 PM, Jose tomas R. <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
 
Josh Cheek
Guest
Posts: n/a
 
      01-03-2011
[Note: parts of this message were removed to make it a legal post.]

On Mon, Jan 3, 2011 at 12:38 PM, Phillip Gawlowski <
http://www.velocityreviews.com/forums/(E-Mail Removed)> 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.

 
Reply With Quote
 
Phillip Gawlowski
Guest
Posts: n/a
 
      01-03-2011
On Mon, Jan 3, 2011 at 8:11 PM, Josh Cheek <(E-Mail Removed)> 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.

 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      01-04-2011
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
license file never validates as true Jon Paal ASP .Net 0 08-30-2006 05:32 PM
User validates to local server when NTLM authentication is used andbrowser is firefox Buddy Ackerman ASP .Net 2 05-12-2005 05:11 PM
confused - html validates, css validates but validate css from the html causes errors Titus A Ducksass - AKA broken-record HTML 6 11-15-2004 12:59 PM
validates characters Lyle Ladeira C++ 6 07-30-2004 12:55 PM
Now it validates! Richard HTML 11 01-14-2004 10:11 PM



Advertisments