Skip to content

Instantly share code, notes, and snippets.

@billturner
Created December 22, 2009 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billturner/261795 to your computer and use it in GitHub Desktop.
Save billturner/261795 to your computer and use it in GitHub Desktop.
%dl
%dt
=f.label :title, :caption => "Post Title"
%dd
=f.text_field :title, :value => @post.title, :size => 50
%dt
=f.label :body, :caption => "Post Body"
%dd
=find_and_preserve do
=f.text_area :body
%dt
=f.submit "Submit"
# the Post.new here, doesn't give the "body" property any content, so, nil.
get '/new_post' do
authenticate!
@page_title = "Add Post"
@post = Post.new
haml :new_post
end
post '/new_post' do
authenticate!
@post = Post.create(params[:post])
redirect '/'
end
# but this will create an empty, and correct, tag:
get '/new_post' do
authenticate!
@page_title = "Add Post"
@post = Post.new(:body => '')
haml :new_post
end
-form_for @post, "/edit_post/#{@post.id}", :method => 'POST', :class => "admin-form" do |f|
=partial 'post_form', :object => @post, :locals => { :f => f }
class Post
include DataMapper::Resource
property :id, Serial
property :title, String, :length => 255
property :slug, String, :length => 255
property :body, Text
property :created_at, DateTime
property :updated_at, DateTime
end
<!--
here the textarea tag is prematurely closed, which
Firefox doesn't seem to like. You can see the result in
this screenshot:
http://farm5.static.flickr.com/4029/4207451802_188bc71a76_o.png
-->
<textarea name="post[body]" id="post_body" />
@mtthwkfmn
Copy link

THanks for the excellent code, HAML, and http://farm5.static.flickr.com/4029/4207451802_188bc71a76_o.png shot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment