Another day with merb and merb-assets
Posted by Nucc
I had a long morning with javascripts helpers. Two days ago, I had installed merb-0.9.0, because I have would try to probe what new features get. The main changes is the separation of merb and merb-gen. The scripts directory was removed, and we can generate models, controllers, … with merb-gen.
merb-gen project cd project merb-gen model user
It was long time, until I found this. I started to write some models, controllers, and views. And views… This cause my long-long morning. In merb, we can seperate the javascript code and the layout. It’s very important, when we have a lot of views with one common layout. Let’s look, how does it work… First, (it’s very important!!!) we need to set in config/init.rb
-
dependency "merb-assets"
It contains our javascript helpers. In merb we can set bundles, but this is another story. Next, we create the layout, it will be a very simple layout…
-
<html>
-
<head>
-
<title> Project </title>
-
<%= include_required_js %>
-
</head>
-
<body>
-
<%= catch_content :for_layout %>
-
</body>
-
</html>
include_required_js is a target, that will insert the
Let us look the Users/create view. In this view, we will use prototype framework.
-
<%- require_js "prototype" %>
-
-
<div id="content">
-
blablabla
-
</div>
And the result:
-
<html>
-
<head>
-
<title> Project </title>
-
<script src="/javascripts/prototype.js" type="text/javascript"></script>
-
</head>
-
<body>
-
<%= catch_content :for_layout %>
-
</body>
-
</html>
It was 4 hour in the morning, I downloaded the newest version from git, and the solution was dependency merb-assets. But works ![]()