title: Creation of user profile page with Meteor and Iron Router
body: <p>I'm building a web app with Meteor and the Iron Router and one of my goals is to build a profile view for the user that's logged in (where he can edit his info) and profile view for all the users (which can be viewed by any person).</p>
  
  <p>The profile view of the user logged in works well, but I'm having problems in creating the user profile view for the other users. When I try to access directly in the browser to some user profile with the url (<code>eg: localhost:3000/users/"id"</code>) it renders the data of the user logged in and the url in the browser changes to localhost:<code>3000/users/[object%20Object]</code>.</p>
  
  <p>Also the  tag with the reference to the is always empty when the page with that info is rendered.</p>
  
  <p>Here is the code related with this problem:</p>
  
  <p>server - <code>publications.js</code></p>
  
  <pre><code>Meteor.publish('singleUser', function(userId) {
     return Meteor.users.find(userId);
  });
  </code></pre>
  
  <p>router.js</p>
  
  <pre><code>Router.map(function() { 
      this.route('profile', {
          path:'/profile',
          data: function() {return Meteor.user();}
      });
  
      this.route('user_profile', {
          path: '/users/:_id',
          waitOn: function() {
                  return Meteor.subscribe('singleUser', this.params._id);
          },
          data: function() { 
                  var findById = Meteor.users.findOne(this.params._id);
                  if (typeof findById !== "undefined") {
               Router.go(getProfileUrlById(findById),  {replaceState: true});
                  }
          }
      }); 
  });
  </code></pre>
  
  <p>User Profile template</p>
  
  <pre><code>&lt;template name="user_profile"&gt;
      &lt;h4&gt;Username&lt;/h4&gt;
      &lt;p&gt;{{username}}&lt;/p&gt;
      &lt;h4&gt;Email:&lt;/h4&gt;
      &lt;p&gt;{{email}}&lt;/p&gt;    
  &lt;/template&gt; 
  </code></pre>
  
  <p>User Profile Helpers</p>
  
  <pre><code>Template.user_profile.helpers({
       username: function() {return Meteor.user().username},
       email: function() {return Meteor.user().emails[0].address} 
  });
  </code></pre>
  
  <p>Item template</p>
  
  <pre><code>&lt;template name="item"&gt;
      &lt;/span&gt; &lt;a href="{{profileUrl}}"&gt;{{author}}&lt;/a&gt;
  &lt;/template&gt; 
  </code></pre>
  
  <p>Item Helpers</p>
  
  <pre><code>Template.item.helpers({
      profileUrl: function() {
          var user = Meteor.users.findOne(this.userId, {reactive:false});
          if(user)
              return getProfileUrlById(user);
      }
   });
  
  getProfileUrlById = function(id) {
      return Meteor.absoluteUrl()+'users/' + id;
  }
  </code></pre>
  
  <p>User Profile logged in template</p>
  
  <pre><code>&lt;template name="profile"&gt;
      &lt;h4&gt;Username&lt;/h4&gt;
      &lt;p&gt;{{username}}&lt;/p&gt;
      &lt;h4&gt;Email:&lt;/h4&gt;
      &lt;p&gt;{{email}}&lt;/p&gt;
  &lt;/template&gt;
  </code></pre>
  
  <p>User Profile logged in helpers</p>
  
  <pre><code>Template.profile.helpers({
      username: function() {return Meteor.user().username},
      email: function() {return Meteor.user().emails[0].address}
   });
  </code></pre>
  
  <p>Am I missing something?</p>
  
  <p>Thanks in advance!</p>