Created
September 10, 2009 08:26
-
-
Save raecoo/184413 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
# i18n | |
en: | |
activerecord: | |
models: | |
topic: Topic | |
attributes: | |
topic: | |
posts_body: Body | |
# topic | |
class Topic < ActiveRecord::Base | |
attr_accessor :body | |
has_many :posts, :autosave => true | |
validates_presence_of :title | |
end | |
# post | |
class Post < ActiveRecord::Base | |
belongs_to :topic | |
validates_presence_of :body | |
end | |
# topic_controller/create action | |
def create | |
@topic = Topic.new(params[:topic]) | |
@topic.posts << Post.new(:body => params[:topic][:body]) | |
@topic.save ? redirect_to(@topic) : render :action => :new | |
end | |
# new.html.erb | |
<h1>Create new topic</h1> | |
<%= error_messages_for :topic %> | |
<% form_for @topic do |f| -%> | |
<p> | |
<label>title</label><br/> | |
<%= f.text_field :title %> | |
</p> | |
<p> | |
<label>body</label><br/> | |
<%= f.text_area :body %> | |
</p> | |
<p> | |
<%= f.submit 'create' %> | |
</p> | |
<% end -%> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment