Created
December 22, 2009 15:23
-
-
Save billturner/261795 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-form_for @post, "/edit_post/#{@post.id}", :method => 'POST', :class => "admin-form" do |f| | |
=partial 'post_form', :object => @post, :locals => { :f => f } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
THanks for the excellent code, HAML, and http://farm5.static.flickr.com/4029/4207451802_188bc71a76_o.png shot!