Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Problem rendering template with redirectTo #201

Closed
thiagopnts opened this Issue · 8 comments

4 participants

Thiago Pontes Paul Miller Mathias Schäfer Andreas Cederström
Thiago Pontes

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?

Paul Miller
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.

Thiago Pontes

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'
Mathias Schäfer
Owner

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

Thiago Pontes

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.

Andreas Cederström

how does your with_user helper look like?

Thiago Pontes

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)
Andreas Cederström

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

try:

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

Paul Miller
Owner

Closing as worksforme.

Paul Miller 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.