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
Truncate String When It Is Too Long
How to Interact with a Caldav Server from Ruby
Gem Install Pg for Ruby on Rails
How to Specify Regexp Options Using Regexp.Union
How to Display Image Pointed by Url in Rails
Using a Self-Signed Certificate
Setting Up Configuration Settings When Writing a Gem
Error Installing Ruby in Yosemite
Heroku Repo Size and Slug Size Increase with Each Deployment. Why
Capybara & Cucumber | Getting Cookies
Ruby-Open3.Popen3/How to Print The Output
How to Get All Message History from Hipchat for a Room via The API
Best/Most Elegant Way to Share Objects Between a Stack of Rack Mounted Apps/Middlewares
What Ruby Technique Does Rails Use to Make My Controller Methods Render Views
Undefined Method 'Merge' for '####':String <%= Form_For %> Helper
Can Optionparser Skip Unknown Options, to Be Processed Later in a Ruby Program
How to Programmatically Remove "Singleton Information" on an Instance to Make It Marshal