Scaffolding in Merb... Any Tutorial available

9 views
Skip to first unread message

MyMerb

unread,
Sep 26, 2008, 4:14:53 AM9/26/08
to merb
Hi,

I an currently in my learning process for Merb and Active Record.

So far... I have not seen any tutorial on Scaffolding in Merb.

Can few experienced folks point me out few good links or Blogs or
Tutorials on this subject.

Thanks

Michael Klishin

unread,
Sep 26, 2008, 4:16:53 AM9/26/08
to me...@googlegroups.com
2008/9/26 MyMerb <mym...@gmail.com>:

> So far... I have not seen any tutorial on Scaffolding in Merb.

run merb-gen without arguments to see generators available on your system.
Additional gems may provide their own generators.
--
MK

Matt Aimonetti

unread,
Sep 26, 2008, 8:06:40 PM9/26/08
to me...@googlegroups.com
FYI and to add to what Michael just said:

merb-gen resource Bird name:string color:string family_id:integer last_location:string last_seen_at:datetime

merb-gen AR template uses  the same syntax as Rails generator.

-Matt

Arun

unread,
Nov 12, 2008, 3:26:40 PM11/12/08
to merb
> merb-gen resource Bird name:string color:string family_id:integer
> last_location:string last_seen_at:datetime
"merb-gen resource" gives the error:

FATAL: The file dm-core was not found

config/database.yml specify:

use_orm :activerecord

>
> merb-gen AR template uses  the same syntax as Rails generator.
merb-gen does not seem to show any help on this. Can you expand more
here ?

-Arun
>
> -Matt
>
> On Fri, Sep 26, 2008 at 1:16 AM, Michael Klishin <
>

Arun

unread,
Nov 12, 2008, 3:42:25 PM11/12/08
to merb
jruby -S merb-gen model --orm activerecord Runner distance:float
minutes:integer

still showing the same error message.

Any idea ?

Matt Aimonetti

unread,
Nov 12, 2008, 3:47:12 PM11/12/08
to me...@googlegroups.com
not sure, but merb-gen arguments are comma delimited and without space (yeah, I know it sucks :()

try:

jruby -S merb-gen model --orm activerecord Runner distance:float,minutes:integer

and

jruby -S merb-gen model Runner distance:float,minutes:integer

-Matt

Arun

unread,
Nov 12, 2008, 7:31:50 PM11/12/08
to merb
Subtle ;-)

Anyway, still getting the same error ...

../../../bin/jruby -S merb-gen model --orm activerecord Runner
distance:float,minutes:integer
Loading init file from /Users/arungupta/samples/jruby/merb/jruby-1.1.5/
samples/merb/hello/config/init.rb
Loading /Users/arungupta/samples/jruby/merb/jruby-1.1.5/samples/merb/
hello/config/environments/development.rb
~
~ FATAL: The file dm-core was not found
~

config/init.rb is already configured to use activerecord.

What's missing ?

-Arun

On Nov 12, 2:47 pm, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> not sure, but merb-gen arguments are comma delimited and without space
> (yeah, I know it sucks :()
>
> try:
>
> jruby -S merb-gen model --orm activerecord Runner
> distance:float,minutes:integer
>
> and
>
> jruby -S merb-gen model Runner distance:float,minutes:integer
>
> -Matt
>

Matt Aimonetti

unread,
Nov 12, 2008, 7:36:31 PM11/12/08
to me...@googlegroups.com
I'm not sure, you might have some other dependencies requiring dm, can I see your init.rb/dependencies.rb files please?

-Matt

Arun

unread,
Nov 12, 2008, 7:48:49 PM11/12/08
to merb
Ah, that explains!

depdencies.rb has:

dependency "dm-core", dm_gems_version
dependency "dm-aggregates", dm_gems_version
dependency "dm-migrations", dm_gems_version
dependency "dm-timestamps", dm_gems_version
dependency "dm-types", dm_gems_version
dependency "dm-validations", dm_gems_version

How do I DRY up my application and specify pluggable ORM once ?

If I comment these lines then the model is correctly generated.

-Arun

On Nov 12, 6:36 pm, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> I'm not sure, you might have some other dependencies requiring dm, can I see
> your init.rb/dependencies.rb files please?
>
> -Matt
>

Matt Aimonetti

unread,
Nov 12, 2008, 7:57:13 PM11/12/08
to me...@googlegroups.com
you should have just done:

$ merb-gen core --orm activerecord my_app_name

and just add what you need, using merb-gen app  generates a merb stack app with DM, since you don't want to use DM a core app is better.

-Matt

Arun

unread,
Nov 12, 2008, 8:08:59 PM11/12/08
to merb
Ah excellent, just what I needed :)

Can I specify database at the CLI as well ? For example MySQL instead
of SQLite3.

-Arun

On Nov 12, 6:57 pm, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> you should have just done:
>
> $ merb-gen core --orm activerecord my_app_name
>
> and just add what you need, using merb-gen app  generates a merb stack app
> with DM, since you don't want to use DM a core app is better.
>
> -Matt
>

Arun

unread,
Nov 12, 2008, 8:14:59 PM11/12/08
to merb
Also, there is no config/database.yml in this case. Where is the
database information specified ? Or specifically what is database.yml
equivalent in this case ?

-Arun

On Nov 12, 6:57 pm, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> you should have just done:
>
> $ merb-gen core --orm activerecord my_app_name
>
> and just add what you need, using merb-gen app  generates a merb stack app
> with DM, since you don't want to use DM a core app is better.
>
> -Matt
>

Matt Aimonetti

unread,
Nov 12, 2008, 8:24:56 PM11/12/08
to me...@googlegroups.com
look at the rake task to generate a new database.yml file. The generator belongs to merb_activerecord

-Matt

Michael Klishin

unread,
Nov 12, 2008, 8:32:56 PM11/12/08
to me...@googlegroups.com
> Also, there is no config/database.yml in this case.

This has it's reasoning: in the end teams of developers end up keeping
database.yml ignored in SCM
because it's hard to use absolutely the same set up across different
machines. The most obvious example is
a socket file that is stored in different locations depending on how
you did install MySQL, PostgreSQL or whatever it is.

MacPorts use one path, Debian packages use some other, building from
source results in some 3rd location. So it's environment specific.
--
MK

Arun

unread,
Nov 12, 2008, 11:35:07 PM11/12/08
to merb
OK, that makes sense, thanks!

On Nov 12, 7:32 pm, "Michael Klishin" <michael.s.klis...@gmail.com>
wrote:

Arun

unread,
Nov 13, 2008, 12:27:46 AM11/13/08
to merb
The generated [index,new,show,edit].html.erb do not seem to have any
code in there.

How can I ensure that the right set of code is generated as well ?

-Arun

On Nov 12, 2:47 pm, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> not sure, but merb-gen arguments are comma delimited and without space
> (yeah, I know it sucks :()
>
> try:
>
> jruby -S merb-gen model --orm activerecord Runner
> distance:float,minutes:integer
>
> and
>
> jruby -S merb-gen model Runner distance:float,minutes:integer
>
> -Matt
>

Arun

unread,
Nov 17, 2008, 2:00:43 PM11/17/08
to merb
Added a simple new view as described at:

http://wiki.merbivore.com/howto/simple_new_view

The code looks like:

-- cut here --
<%= form_for(@runner, :action => resource(:runners) ) do %>

<p>
<%= text_field :distance, :label => "Distance" %>
</p>

<p>
<%= text_field :minutes, :label => "Minutes" %>
</p>

<p>
<%= submit "Create" %>
</p>
<% end =%>

<%= link_to 'Back', resource(:runners) %>
-- cut here --

Also added an entry:

resources :runners

in config/router.rb

Still getting the following error:

-- cut here --
No Method Error 500
undefined method `form_for' for #<Runners:0x197a120>

All App Framework Gem Other

app/views/runners/new.html.erb (ERB Template) 5

1<h1>Runners controller, new action</h1> 2 3<p>Edit this file in
<tt>app/views/runners/new.html.erb</tt></p> 4 5<%= form_for
(@runner, :action => resource(:runners) ) do %> 6 7 <p> 8 <%=
text_field :distance, :label => "Distance" %> 9 </p> 10
-- cut here --

What's missing ?

-Arun

Matt Aimonetti

unread,
Nov 17, 2008, 2:10:54 PM11/17/08
to me...@googlegroups.com
can you show us your controller, I won't what is @runner, in theory it should be an instance of your Runner class.

-Matt

Michael Klishin

unread,
Nov 17, 2008, 2:40:39 PM11/17/08
to me...@googlegroups.com
2008/11/17 Arun <arun....@gmail.com>:

> No Method Error 500
> undefined method `form_for' for #<Runners:0x197a120>
> What's missing ?

Either merb-helpers is not loaded at all, or (for some very weird
reason) default form builder is not set.
--
MK

Matt Aimonetti

unread,
Nov 17, 2008, 2:55:47 PM11/17/08
to me...@googlegroups.com
hmm good catch, if you generated a stack app, merb-helpers and merb-assets won't be declared as dependencies.

-Matt

Arun

unread,
Nov 17, 2008, 3:25:17 PM11/17/08
to merb
Stock runner generated as:

-- cut here --
class Runners < Application
# provides :xml, :yaml, :js

# GET /runners
def index
@runners = Runner.find(:all)
display @runners
end

# GET /runners/:id
def show
@runner = Runner.find_by_id(params[:id])
raise NotFound unless @runner
display @runner
end

# GET /runners/new
def new
only_provides :html
@runner = Runner.new(params[:runner])
render
end

# POST /runners
def create
@runner = Runner.new(params[:runner])
if @runner.save
redirect url(:runner, @runner)
else
render :new
end
end

# GET /runners/:id/edit
def edit
only_provides :html
@runner = Runner.find_by_id(params[:id])
raise NotFound unless @runner
render
end

# PUT /runners/:id
def update
@runner = Runner.find_by_id(params[:id])
raise NotFound unless @runner
if @runner.update_attributes(params[:runner])
redirect url(:runner, @runner)
else
raise BadRequest
end
end

# DELETE /runners/:id
def destroy
@runner = Runner.find_by_id(params[:id])
raise NotFound unless @runner
if @runner.destroy
redirect url(:runners)
else
raise BadRequest
end
end

end
-- cut here --

-Arun
On Nov 17, 11:10 am, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> can you show us your controller, I won't what is @runner, in theory it
> should be an instance of your Runner class.
>
> -Matt
>

Matt Aimonetti

unread,
Nov 17, 2008, 3:27:13 PM11/17/08
to me...@googlegroups.com
can you also show us your init.rb or dependencies.rb   it should list merb-helpers and probably merb-assets

-Matt

Arun

unread,
Nov 17, 2008, 3:27:22 PM11/17/08
to merb
I added merb-assets already, now added merb-helpers as well but still
seeing the same error.

MRI and JRuby gives the same result. This app is generated using "core
app" and is using ActiveRecord as ORM.

-Arun

On Nov 17, 11:55 am, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> hmm good catch, if you generated a stack app, merb-helpers and merb-assets
> won't be declared as dependencies.
>
> -Matt
>
> On Mon, Nov 17, 2008 at 2:40 PM, Michael Klishin <
>
> michael.s.klis...@gmail.com> wrote:
>
> > 2008/11/17 Arun <arun.gu...@gmail.com>:

Arun

unread,
Nov 17, 2008, 3:30:31 PM11/17/08
to merb
Ah, figured out.

I created a new file config/dependencies.rb and specified:

dependency "merb-assets", "1.0"
dependency "merb-helpers", "1.0"

If I include these in config/init.rb, then a new runner can be
created.

It seems like dependencies.rb is not picked up for a core app.

-Arun

On Nov 17, 11:55 am, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> hmm good catch, if you generated a stack app, merb-helpers and merb-assets
> won't be declared as dependencies.
>
> -Matt
>
> On Mon, Nov 17, 2008 at 2:40 PM, Michael Klishin <
>
> michael.s.klis...@gmail.com> wrote:
>
> > 2008/11/17 Arun <arun.gu...@gmail.com>:

Michael Klishin

unread,
Nov 17, 2008, 3:32:15 PM11/17/08
to me...@googlegroups.com
2008/11/17 Arun <arun....@gmail.com>:

> MRI and JRuby gives the same result. This app is generated using "core
> app" and is using ActiveRecord as ORM.

Both should not matter here. What is in your init file?
--
MK

Michael Klishin

unread,
Nov 17, 2008, 3:33:04 PM11/17/08
to me...@googlegroups.com
2008/11/17 Arun <arun....@gmail.com>:

> It seems like dependencies.rb is not picked up for a core app.

If you cannot find require 'dependencies' in init.rb then yes, it's a
generated template issue.
--
MK

Matt Aimonetti

unread,
Nov 17, 2008, 3:44:20 PM11/17/08
to me...@googlegroups.com
Arun,

 I think you are making a good point, we made merb stack really easy, but if you want to use a core app, you have to know your way around.

I think we should:

1. write better documentation for your use case
2. make an example app available for people to look at

What do you think?

-Matt

Arun

unread,
Nov 17, 2008, 4:55:08 PM11/17/08
to merb
new/show/edit actions are now working correctly but index is giving
the error:

-- cut here --
app/views/runners/index.html.erb (ERB Template) 19

14 <td><%=h runner.distance %></td>
15 <td><%=h runner.minutes %></td>
16
17 <td><%= link_to 'Show', resource(runner) %></td>
18 <td><%= link_to 'Edit', resource(runner, :edit) %></td>
19 <td><%= delete_button(runner, "Delete #{runner.title}") %></td>
20 </tr>
21<% end %>
22</table>
23
24<%= link_to 'New', resource(:articles, :new) %>

app/views/runners/index.html.erb (ERB Template) 12

7 <th>Time (in mins)</th>
8
9 <th colspan="3">Actions</th>
10 </tr>
11
12<% @runners.each do |runner| %>
13 <tr>
14 <td><%=h runner.distance %></td>
15 <td><%=h runner.minutes %></td>
16
17 <td><%= link_to 'Show', resource(runner) %></td>

app/views/runners/index.html.erb (ERB Template) 12

7 <th>Time (in mins)</th>
8
9 <th colspan="3">Actions</th>
10 </tr>
11
12<% @runners.each do |runner| %>
13 <tr>
14 <td><%=h runner.distance %></td>
15 <td><%=h runner.minutes %></td>
16
17 <td><%= link_to 'Show', resource(runner) %></td>

app/controllers/runners.rb in `index' 7

2 # provides :xml, :yaml, :js
3
4 # GET /runners 5 def index
6 @runners = Runner.find(:all)
7 display @runners
8 end
9
10 # GET /runners/:id
11 def show
12 @runner = Runner.find_by_id(params[:id])
-- cut here --

-Arun

On Nov 17, 12:32 pm, "Michael Klishin" <michael.s.klis...@gmail.com>
wrote:
> 2008/11/17 Arun <arun.gu...@gmail.com>:
>

Arun

unread,
Nov 17, 2008, 5:15:55 PM11/17/08
to merb
Sure, I completely agree with both the points.

I'm working on a blog entry as the questions are getting answered.
I'll be happy to share the application as well.

Almost the last piece of puzzle is missing (index not showing up
properly) and then will clean up the entry and push it.

-Arun

On Nov 17, 12:44 pm, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> Arun,
>
>  I think you are making a good point, we made merb stack really easy, but if
> you want to use a core app, you have to know your way around.
>
> I think we should:
>
> 1. write better documentation for your use case
> 2. make an example app available for people to look at
>
> What do you think?
>
> -Matt
>
> On Mon, Nov 17, 2008 at 3:33 PM, Michael Klishin <
>
> michael.s.klis...@gmail.com> wrote:
>
> > 2008/11/17 Arun <arun.gu...@gmail.com>:

Arun

unread,
Nov 17, 2008, 6:17:14 PM11/17/08
to merb
Yep, seems like.

require 'config/dependencies.rb' is missing from core app.

If I add it then everything works.

-Arun

On Nov 17, 12:33 pm, "Michael Klishin" <michael.s.klis...@gmail.com>
wrote:
> 2008/11/17 Arun <arun.gu...@gmail.com>:
>

Dick Davies

unread,
Nov 18, 2008, 8:17:01 AM11/18/08
to me...@googlegroups.com
Just an observation:

This all seems to stem from 'merb-gen app' being incompatible with JRuby,
which at the root is because DataMapper doesn't support JRuby.
This means any newbies trying out merb + jruby get forced down the 'hardcore'
path of 'merb-gen core'.

Would providing an --orm option to 'merb-gen app' prevent this?

[ Really glad to see merb and JRuby playing nicer together, BTW;
thanks to everyone who's been putting the effort in ].

Arun

unread,
Nov 18, 2008, 9:07:42 AM11/18/08
to merb
I finally published a blog highlighting all the steps for creating a
scaffold using JRuby/GlassFish at;

http://blogs.sun.com/arungupta/entry/totd_53_scaffold_in_merb

Dick,

I mentioned --orm switch at:

http://groups.google.com/group/merb/browse_thread/thread/8cd0ea8cf6f43bd1#

and I think will be really great!

Thanks,
-Arun

On Nov 18, 5:17 am, "Dick Davies" <rasput...@gmail.com> wrote:
> Just an observation:
>
> This all seems to stem from 'merb-gen app' being incompatible with JRuby,
> which at the root is because DataMapper doesn't support JRuby.
> This means any newbies trying out merb + jruby get forced down the 'hardcore'
> path of 'merb-gen core'.
>
> Would providing an --orm option to 'merb-gen app' prevent this?
>
> [ Really glad to see merb and JRuby playing nicer together, BTW;
> thanks to everyone who's been putting the effort in ].
>
> On Mon, Nov 17, 2008 at 8:44 PM, Matt Aimonetti <mattaimone...@gmail.com> wrote:
> > Arun,
>
> >  I think you are making a good point, we made merb stack really easy, but if
> > you want to use a core app, you have to know your way around.
>
> > I think we should:
>
> > 1. write better documentation for your use case
> > 2. make an example app available for people to look at
>
> > What do you think?
>
> > -Matt
>
> > On Mon, Nov 17, 2008 at 3:33 PM, Michael Klishin
> > <michael.s.klis...@gmail.com> wrote:
>
> >> 2008/11/17 Arun <arun.gu...@gmail.com>:

Dick Davies

unread,
Nov 18, 2008, 10:41:29 AM11/18/08
to me...@googlegroups.com
On Tue, Nov 18, 2008 at 2:07 PM, Arun <arun....@gmail.com> wrote:

Hi Arun

that's a separate issue; I'm saying that on JRuby,
you have to use 'merb-gen core' because 'merb-gen app' has no '--orm' option
(since it's supposed to be t 'quickstart' option).

The 'core' path is harder for new users (as it should be; that's the
'roll your own' option) ;
hence the workarounds you've described to get scaffolding working.

If merb-gen app took an --orm option, there'd be no need for JRuby users
to run 'merb-gen core' so early on in their Merb careers.

Arun

unread,
Nov 18, 2008, 1:35:26 PM11/18/08
to merb
Aboslutely, "merb-gen app --orm activerecord" would be ideal.

I suggested that somewhere but can't find the reference now :) But I
completely agree with your recommendation. This will also include the
relevant dependencies and no workaround will be required.

-Arun

On Nov 18, 7:41 am, "Dick Davies" <rasput...@gmail.com> wrote:
> On Tue, Nov 18, 2008 at 2:07 PM, Arun <arun.gu...@gmail.com> wrote:
> > Dick,
>
> > I mentioned --orm switch at:
>
> >http://groups.google.com/group/merb/browse_thread/thread/8cd0ea8cf6f4...

Michael Klishin

unread,
Nov 18, 2008, 2:59:44 PM11/18/08
to me...@googlegroups.com
2008/11/18 Dick Davies <rasp...@gmail.com>:

>
> Just an observation:
>
> This all seems to stem from 'merb-gen app' being incompatible with JRuby,
> which at the root is because DataMapper doesn't support JRuby.
> This means any newbies trying out merb + jruby get forced down the 'hardcore'
> path of 'merb-gen core'.

Not sure how hardcore is replacing a few characters on the command
line. If we bring --orm option
back to merb stack generator, that generator would not make any sense:
it would make it virtually
non different from the "core" generator.

merb-gen generators list mentions what every generator does.
--
MK

Dick Davies

unread,
Nov 19, 2008, 9:44:55 AM11/19/08
to me...@googlegroups.com
On Tue, Nov 18, 2008 at 7:59 PM, Michael Klishin
<michael....@gmail.com> wrote:
>
> 2008/11/18 Dick Davies <rasp...@gmail.com>:

>> newbies trying out merb + jruby get forced down the 'hardcore'
>> path of 'merb-gen core'.
>
> Not sure how hardcore is replacing a few characters on the command
> line.

Sorry if I misunderstood, but I thought running 'merb-gen core' meant you
had to write the scaffolding code by hand, edit config/init.db to add
dependencies , etc.

> If we bring --orm option
> back to merb stack generator, that generator would not make any sense:
> it would make it virtually non different from the "core" generator.

Point taken, it was just a thought.

Michael Klishin

unread,
Nov 19, 2008, 10:18:02 AM11/19/08
to me...@googlegroups.com
2008/11/19 Dick Davies <rasp...@gmail.com>:

> Sorry if I misunderstood, but I thought running 'merb-gen core' meant you
> had to write the scaffolding code by hand, edit config/init.db to add
> dependencies , etc.

Correct, and it is intentional. Core generator lets you pick
components you want:
I have a few small applications that only use merb-core, sequel and
merb-messenger, all for
22 megs of ram.
--
MK

Reply all
Reply to author
Forward
0 new messages