You can replace URL(...,args=id) with URL(...,vars=dict(id=id)) and
request.args(0) with request.vars.id.

I prefer the more restful syntax but there is no deep reason.

Massimo

On Aug 11, 3:37 pm, __future__ <wrigh...@gmail.com> wrote:
> Thanks a lot for that detailed explanation...
>
> Why do we use args instead of request.vars?  Wouldn't using the
> request vars allow using named values in the controller?  It is not
> the biggest thing in the world but whenever I see something like args
> (0), I feel like I am reading perl.  I hate reading perl. :)
>
> __future__
>
> On Aug 11, 9:43 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > >     if db((db.attendance.event==event_id) & 
> > > (db.attendance.user==auth.user.id)).delete():
> > >         return 'Not Attending'
> > >     else:
> > >         db.attendance.insert(event=event_id, user=auth.user.id)
> > >         return 'Attending'
>
> > > This obviously works but looks backwards to me for some reason.  What
> > > am I missing?
>
> > db().delete() returns the number of affected records. If it returns 0
> > then there are no records to delete and it assumes you meant to insert
> > one, not delete one. This is the same as your code. I just removed the
> > explicit check.
>
> > > In the view:
>
> > >     <button id="x{{=item.event.id}}"onclick="ajax(
> > >         '{{=URL(r=request,f='toggle_attendance',
> > >             args=item.event.id)}}',[],'x{{=item.event.id}}');">
>
> > > Can you step me through what is going on here.
>
> > This is a bit tricky. Say you have an item.event.id==1. Then it make a
> > button
>
> > <button id="x1" onclick="ajax('/yourapp/default/'toggle_attendance/1',
> > [],'x1')">...</button>
>
> > that when clicked sends anajaxrequest to /yourapp/
> > default/'toggle_attendance/1. The /1 implies request.args(0)=1. []
> > means it passes no request.vars. The last argument ofajax(...,'x1')
> > means that the value returned by theajaxfunction goes into the
> > innerHTML of the tag with id=='x1'.
> > So basically when you click the button is calls the server, the server
> > creates or deletes the record and returns the new name for the button.
>
> > > I'm not sure
> > > understand how the helpers work withajax.  I get that you are
> > > creating a 'button' and that it is passing the event.id to the toggle
> > > function.  I guess my confusion is still the confusion about how the
> > > toggle is deciding what to return.  It seems like if it successfully
> > > deletes the attendance record, it returns that there IS an attendance,
> > > and if it inserts an attendance record it returns that is NOT an
> > > attendance.  This is not what actually happens so why am I reading it
> > > this way?  I also don't understand where what is actually returned is
> > > represented in the view.
>
> > Sorry. I had a type "Unattending" instead of "Attending".
>
> > Hope this makes more sense.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to