Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Problem rendering template with redirectTo #201

Closed
thiagopnts opened this Issue · 8 comments

4 participants

@thiagopnts

Hey guys, I have the following view: https://gist.github.com/3784352, with this template: https://gist.github.com/3784360

When I try /home directly in the browser everything works fine, the content from the #with_user is rendered, but when I redirect from / to /home through redirectTo method it doesn't render the content from #with_user helper. Any thoughts?

@paulmillr
Owner

I think you are probably forgetting about async nature of getting current user from mediator. It can be that user just ain't fetched in time you are rendering the template.

@thiagopnts

It could be, but I had this problem in mind when I implemented it, this was my approach, I render this view as a collection view, it works when accessing the page directly, but fails when after a redirect:

renderSubviews: ->
    $("#loading").show()
    feeds = new Feeds
    feeds.url = if mediator.user? then "/feeds/#{mediator.user.id}" else ""

    feeds.fetch({success: -> $("#loading").hide()})

    @subview 'topbar', new TopbarView
    @subview 'status', new NewStatusView

    @subview 'feeds', new FeedsView
      collection: feeds
      container: '.feeds'
@molily
Owner

@thiagopnts Were you able to isolate the problem? Is mediator.user undefined after the redirect? Can you investigate how that can happen?

@thiagopnts

I could try to isolate it. For now I made a workaround on it, by just not using #with_user helper. I'm still passing mediator in getTemplateData, the problem was that when I use redirectTo, handlebars helper method #with_user wasn't called.

@andriijas

how does your with_user helper look like?

@thiagopnts

Hi andriijas, it was like this:

Handlebars.registerHelper 'with_user', (options) ->
  console.log 'with_user helper'

  context = mediator.user.attributes
  Handlebars.helpers.with.call(this, context, options)
@andriijas

if the user is not logged in mediator.user will probably null.

try:

context = mediator.user?.serialize() or {}

@paulmillr
Owner

Closing as worksforme.

@paulmillr paulmillr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.