-
2 weeks 2 days
-
2 weeks 4 days
-
4 weeks 2 days
-
4 weeks 5 days
-
4 weeks 6 days
Merb's Partial
UPDATE: This post has become unstable due to migration, I don't think it'll be any use.
As usual I'm still playing with Merb and I would like to share Merb's partial. Basically its the ability to render objects using a template file that could be used inside several other templates. Hmm.. I hope that went well.
To give you a quick example, lets say your building a blog with a controller named posts and got a posts folder inside your views which contains new.html.erb and edit.html.erb. Your new.html.erb might contain something like:
Add new post
Now in our edit form, those fields are common so it makes more sense (atleast on our example) to use partials. To create a partial, we're going to create _form.html.erb on the same folder as our new.html.erb and edit.html.erb.
There's nothing fancy in here, we're just checking if a post is being pass. If we have a post, we set its value otherwise leave it as an empty string.
Now we can modify our new.html.erb:
Add new post
and edit.html.erb:
Edit new post
As you can see, we call the partial function and pass a symbols that's the same as our partial view. Our optional parameter :with holds what ever value we want to pass on our partial view and this will be accessible via the partial's view name which is form.

Facebook
Twitter
Wow ha! NagruRuby ka na ha.
Wow ha! NagruRuby ka na ha.
Hehehe. Actually I first
Hehehe. Actually I first tried Ruby because of Rails way back 2006, but I didn't have enough reasons to invest more time so Python got my attention mostly.
Post new comment