iron:router returning route path twice? - meteor

I'm accessing iron:router in a helper which builds breadcrumbs, but oddly I'm getting two objects returned when I do this:
console.log(typeof Router.current().route.path(this));
I get back:
object
string
The object is null btw...
Does anyone know why? I think it has something to do with reactivity but I don't know where to look to begin.

I don't really know the answer for this, but easiest breadcrumbs are Iron.Location.get().path.split("/")

While this is not a direct answer to your question, this tutorial covers a lot about iron:router: http://kukuruku.co/hub/javascript/meteor-how-to-build-a-todo-list

Related

Access variables from partial in WebMatrix 2

Quite simply How can I pass from Partial to page on construction:
_SiteLayout.cshtml
#{PageData["phoneNumber"]="072342342343";}
Page.cshtml
please call us on #PageData["phoneNumber"]
Ive tried things like this. What obvious step am I missing?
Its bring up blanks.
try use Session for this:
Session["phoneNumber"]="072342342343"
#Session["phoneNumber"]
You can also use the HttpContext.Items collection. It works about the same as the Session, but the collection is only kept alive for the duration of the request. I'm not sure how to most easily access it using Razor though. Read more about HttpContext.Items here.

SIMPLE MVC Question MVC Redirect

I have a controller that creates a news article. I want to redirect the user to the article's page, something like: "/article/1". Normally I could just throw in return View("MyAction") but I need to pass the integer along in this case. There are overloads for adding a model to the View method call but I don't see anything that will let me accomplish my goal.
What's the best way to do this?
Also, I used ViewData for my success message... if I use a redirect message it isn't going to function so is there a better way to do that too?
I think this is what you might be looking for.
RedirectToAction(new {controller="controllerName", action="article", id=1});
Hope this helps

LINQ to SQL repository - caching data

I have built my first MVC solution and used the repository pattern for retrieving/inserting/updating my database.
I am now in the process of refactoring and I've noticed that a lot of (in fact all) the methods within my repository are hitting the database everytime. This seems overkill and what I'd ideally like is to do is 'cache' the main data object e.g. 'GetAllAdverts' from the database and to then query against this cached object for things like 'FindAdvert(id), AddAdvert(), DeleteAdvert() etc..'
I'd also need to consider updating/deleting/adding records to this cache object and the database.
What is the best apporoach for something like this?
My knowledge of this type of things is minimal and really looking for advice/guidance/tutorial to point me in the right direction.
Thanks in advance.
This just hit my radar, and I assume you have already solved the issue by now. But if not, I would look into Pre-Compiled LINQ Queries. Something like this:
private static Func<SomeDataContext, int, PersonDto> _getPersonByIdQuery =
CompiledQuery.Compile<SomeDataContext, int, PersonDto>(
(dataContext, personId) =>
dataContext.PersonDtos.where(c => c.PersonId == personId).FirstOrDefault()
);
Put something like that inside of your datacontext, then add an internal method in there to call it call it. Your retriever/saver will then call the internal method. Does that make sense? I can post more code if necessary..
Best of luck,
Justin

Why does Flex's ArrayCollection's Contain method look at memory reference?

When using .contains() on an ArrayCollection in Flex, it will always look at the memory reference. It does not appear to look at an .equals() method or .toString() method or anything overridable. Instead, I need to loop through the ArrayCollection every time and check each individual item until I find what I'm looking for.
Does anyone know why Flex/ActionScript was made this way? Why not provide a way from people to use the contains() method the way they want?
Couldn't you just extend ArrayCollection and override the contains() method? Alternatively you can paste the source for ArrayCollection into an "mx/collections" package in your project and modify the source; this "monkey-patching technique" will override the behavior throughout your entire project. However I would be extremely cautious about changing ArrayCollection in that manner: since it's used all over the place in the Flex APIs there is a good chance you'll start breaking other components in the framework.
The contains() method searches by reference, correct (I believe even for primitives), so if you're trying to find a string or an int in an ArrayCollection, you'll have to do the searching yourself, by some variation of looping or searching. I don't think any of us could tell you why there isn't, say, an optional parameter on that method indicating whether to search by ref or by val, though; so it goes, as they say.
But I'd definitely warn you off monkey-patching the framework code -- that's just asking for trouble. :)
Well, it seems like the ArrayCollection doesn't actually look directly at memory, but only as a last resort. It will attempt to find a Unique ID (UID) for the object. If the UID doesn't exist, it will create one for it using the UIDUtil.as.
You can get around this whole default UID stuff by having your object implement the IUID interface and providing your own UID for the object. The ArrayCollection will look at the UID you provide it.
I would suggest a simple:
in_array($haystack, $arrayCollection->toArray());

Updating/Intercepting HttpContext.Current.Request.QueryString

Here's a wierd one. I'm reusing a code base that unfortunately must not be updated. This code makes a call to HttpContext.Current.Request.QueryString. Ideally, I need to push a value into this collection with every request that is made. Is this possible - perhaps in an HTTP Module?
Without using reflection, the simplest way to do it would be to use the RewritePath function on the current HttpContext object in order to modify the querystring.
Using an IHttpModule, it might look something like:
context.RewritePath(context.Request.Path, context.Request.PathInfo, newQueryStringHere!);
Hope this helps!
Ditto Espo's answer and I would like to add that usually in medium trust (specific to many shared hostings) you will not have access to reflection so ... RewritePath will remain your probably only choice.

Resources