Rails 3 - Yield Return or Callback Won't Call in View <%= Yield(:Sidebar) || Render('shared/Sidebar') %>

Rails 3 - yield return or callback won't call in view %= yield(:sidebar) || render('shared/sidebar') %

Ryan Bates from railscasts.com shows in Episode #227 - Upgrading to Rails 3 Part 3 a solution with content_for?() (video playback at 2:45 Min)

I think, that's the way we should use it:

content_for?(:sidebar) ? yield(:sidebar) : render("shared/sidebar")

Is it possible to render a view file from another website?

Yes.

Here is how you might do it.

Create a symlink from the controller's view folder to the partial in the other application.

ln -s path_to_existing/_existingPartial.html.erb path_to_referring/_existingPartial.html.erb

You can now reference the existingPartial in your views as if it were in the same application.

The form will work as long as the target of the form posts to a valid URL in your current directory.

That said, this isn't the best way to do this. A couple other options:

  • Create a Rails plugin both apps use
  • Create a Gem both apps use
  • Depending on your source control software, you can reference the same file in both source trees (for example, using Subversion external references)

Backbone.js - data not being populated in collection even though fetch is successful

fetch is asynchronous, your collection won't yet be populated if you immediately call render. To solve this problem, you just have to bind the collection reset event (sync event for Backbone>=1.0) to the view render :

theView = Backbone.View.extend({
el: $("#temp"),

initialize: function () {
this.collection = new theCollection();

// for Backbone < 1.0
this.collection.on("reset", this.render, this);

// for Backbone >= 1.0
this.collection.on("sync", this.render, this);

this.collection.fetch();
},

render : function () {
console.log( this.collection.toJSON() );
}
});

Note the third argument of the bind method, giving the correct context to the method:
http://documentcloud.github.com/backbone/#FAQ-this



Related Topics



Leave a reply



Submit