Regex in RedirectRoute not working correctly - regex

I have looked into how to use a regex within a RedirectRoute using webapp2. I have tried formatting it the way it says to do so here: http://webapp-improved.appspot.com/guide/routing.html#the-url-template and I still cannot get my regex to work. Here is what I have:
RedirectRoute('/book/<bookId:([0-9]+)><title:(.*)>',handlers.book,name='book')
the call for this is:
self.redirect_to('book/%s_%s' %(bookId,title))
and an example of the url I am expecting is:
book/5907332378656768_The-Wizzard-of-Oz
When I run my app I get the following error:
Error: "Route named u'book/5907332378656768_The-Wizzard-of-Oz' is not defined.
Any help would be greatly appreciated.
EDIT:
Hey everyone! Thanks to Brent's response I was able to fix the problem.
I had to change self.redirect_to('book/%s_%s' %(bookId,title))
to the following: self.redirect('book/%s_%s' %(bookId,title))
Thank you everyone for your help!

A Google search for webapp2 error route "is not defined" finds the Webapp2 source code. That error message is in the method default_builder() which is called from redirect_to(). That method looks for the name field ('book' in this case). Maybe you meant to call redirect() instead?

I think you can leave the parentheses off the patterns:
RedirectRoute('/book/<bookId:[0-9]+><title:.*>',handlers.book,name='book')

Related

Mongoid 4 finding embedded documents by ID

I have a project that is my first serious dive into Mongoid.
I saw a tip to use the following command:
Parent.where('childrens._id' => Moped::BSON::ObjectId(params[:id])).first
But this doesn't work. Error message was:
NameError: uninitialized constant Moped::BSON
I found that BSON is no longer included, so I added it to my Gemfile, as well as Moped. Then, I did another fix I found (placing Moped::BSON=BSON in application.rb).
This still didn't work, but the error changed to:
NoMethodError: undefined method `ObjectId' for BSON:Module
So I am assuming that this method got deprecated or something. Does anyone have any other tips?
Just to be clear, I am finding myself in the situation where I want to sort embedded documents using jquery-sortable. This requires me to update them in the database, but the serialize from that doesn't include the parent document in the hash. So I figured I'd try to get it on the back end using an ID from the embedded document. That is why I need it.
Thanks again for any help you can provide.
Try simply:
Parent.where('childrens._id' => params[:id]).first
I have solved the question though this won't be of much help to people in the future. The requirements have changed and now I am using human-readable strings as IDs to assist in friendly URLs and some other stuff.
Therefore, I don't have any issues with ObjectIds. Cortex's solution should (from what I have read) work for dealing with ObjectIds but I cannot verify it now.

What is the proper way to append view/component to existing view

I have been trying to add a component within a view, I could do it but I am getting some warning message as well like "DEPRECATION: Using the defaultContainer is no longer supported". There is a related post here : emberjs append works but raises Assertion Failed error but not sure what I am doing wrong. Here is my jsbin link : http://jsbin.com/tuwanava/1/
Your help will be very much appreciated. Thanks.
Use
sticky.pushObject(App.ConfirmDeleteComponent.create());

Getting TypeSyntax from TypeSymbol. Do I really need to re-parse the name?

I want to get TypeSyntax from TypeSymbol.
Based on the answer to the Get TypeSyntax from ITypeSymbol question, my solution is Syntax.ParseTypeName(typeSymbol.ToDisplayString()) which doesn't look good.
Is there a more direct solution?
I am not sure if this is what you are looking for but this works forks for me. I get TypeSyntax of declared method parameter using SyntaxReferences this way:
(Symbol.DeclaringSyntaxReferences.First().GetSyntax() as ParameterSyntax).Type

How to delete a record in django within the views?

I'm trying to set up my first CRUD page using django and so far I've got to the D part, respectivly - delete. Following the information found on the internet, I tried this: SomeModel.objects.filter(id=id).delete(), but that threw out an error: id() takes exactly one argument (0 given) so could you tell me what am I doing wrong in order to make it work please?
Thank you.
SomeModel.objects.filter(id=id)[0].delete()

App.get('router').send causing this error Uncaught TypeError: Cannot redefine property: __ember1346884664897

Anyone have any ideas why I'm getting this error:
Uncaught TypeError: Cannot redefine property: __ember1346884664897
when calling:
App.get('router').send('tags')
I'm making the call from one of my views, the router is in the correct state, and as far as I can tell I'm doing everything by the book.
Would really appreciate any ideas...
Created a gist that might help explain things a little better. https://gist.github.com/3647288
App.router.send('something') will look for a function named something in your current state, but you are trying to use route name there. You should have something like showTags in you router and use App.router.send('showTags').
Head to docs http://docs.emberjs.com/#doc=Ember.Router&src=false and look at the part Transitions Between States
I had this problem when I named an action and a state the same way. Perhaps you have the same thing now.