Validates is exists

J

Jose tomas R.

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 )]
 
P

Phillip Gawlowski

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

Josh Cheek

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

On Mon, Jan 3, 2011 at 12:38 PM, Phillip Gawlowski <
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.
 
P

Phillip Gawlowski

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

Brian Candler

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top