If you are trying to get started with Merb and are looking for a good sample app, then have a look at
Cookbook. It's mostly to learn how to use the merb-auth-slice, but can get you started with datamapper too.
DataMapper CRUD
One of the confusing things about Restful resources is that the when changing a resource the operation must be a Post HTTP operation not a Get HTTP. This insures that HTTP Get operations are immutable. OK well how do you do a delete then?
If you create a new merb application, merb-gen app omelet, cd omelet, merb-gen resource egg
The controller already has the destroy action, it's just a matter of calling that with a POST command. There is a Merb form helper called delete_button that can help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
%h1 Users
%table
%thead
%tr
%th Title
%th{:colspan => 2}
%tbody
%tr
- for user in @users
%tr
%td
= user.login
%td
= link_to 'Show', url(:user, user)
%td
= link_to 'Edit', url(:edit_user, user)
%td
= delete_button(user)
= link_to 'New', url(:new_user) |
Now the view will call the destroy action in a Restful manner.
January 27th, 2009 at 11:38 PM Good work! Thank you! I always wanted to write in my site something like that. Can I take part of your post to my blog? Of course, I will add backlink? Regards, Timur I. Alhimenkov