Skip to content
Browse files

one-to-many expanders

  • Loading branch information...
1 parent 874f180 commit e9b301881c60709d63b496c1ba87a324b6a154fd @saltfactory saltfactory committed
View
2 rails/sshb/app/controllers/articles_controller.rb
@@ -30,6 +30,7 @@ def show
def new
@article = Article.new
@article.uuid = SecureRandom.uuid
+ @article.expanders.build({name: 'bible'})
@article.attachments.build({owner: current_user})
end
@@ -108,6 +109,7 @@ def set_board
def article_params
# params.require(:article).permit(:subject, :content, :author_id, :author_type, :board_id, :published)
params.require(:article).permit(:subject, :content, :author_type, :published, :uuid,
+ expanders_attributes:[:value, :name, :id],
attachments_attributes: [:filename, :uuid, :url, :file_file_name, :file_content_type, :file_file_size])
end
end
View
9 rails/sshb/app/views/articles/_form.html.erb
@@ -17,6 +17,15 @@
<%= f.label :subject %><br>
<%= f.text_field :subject, class: "form-control" %>
</div>
+
+ <%= f.fields_for :expanders do |ff|%>
+ <div class="form-group">
+ <%= ff.hidden_field :name %>
+ <%= ff.label :value, ff.object.name %><br>
+ <%= ff.text_field :value, class: "form-control" %>
+ </div>
+ <% end %>
+
<div class="form-group">
<%= f.label :content %><br>
<%= f.text_area :content, class: "form-control", as: :summernote %>
View
2 rails/sshb/app/views/articles/index.html.erb
@@ -32,5 +32,5 @@
</p>
<br>
-
+<%= @board.id %>
<%= link_to 'New Article', new_board_article_path(@board), :"data-no-turbolink" => true %>
View
1 rails/sshb/db/migrate/20160118155446_create_expanders.rb
@@ -2,6 +2,7 @@ class CreateExpanders < ActiveRecord::Migration
def change
create_table :expanders do |t|
t.string :name
+ t.string :text
t.string :value
t.references :expandable, polymorphic: true, index: true
View
1 rails/sshb/db/seeds.rb
@@ -40,6 +40,7 @@
article.board = Board.find_by_slug("sermons")
article.subject = "test sermons"
article.content = "test sermons content"
+ article.expanders << Expander.new({name: "설교말씀"})
end

0 comments on commit e9b3018

Please sign in to comment.
Something went wrong with that request. Please try again.