Skip to content

Instantly share code, notes, and snippets.

@travisdmathis
Last active December 28, 2015 06:29
Show Gist options
  • Select an option

  • Save travisdmathis/7457525 to your computer and use it in GitHub Desktop.

Select an option

Save travisdmathis/7457525 to your computer and use it in GitHub Desktop.
Blog, w/ Categories using Categorization
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @category.name %>
</p>
<%= link_to 'Edit', edit_category_path(@category) %> |
<%= link_to 'Back', categories_path %>
class Categorization < ActiveRecord::Base
belongs_to :post
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :categorizations
has_many :posts, :through => :categorizations
end
class Post < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
end
<div class="container">
<br>
<center>
<div class="well">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">
Create a New Blog Post
</h1>
<div class="row">
<div class="col-md-12">
<%= form_for :post, url: posts_path do |f| %>
<p>
<h4><%= f.label :title %></h4>
<%= f.text_field :title, :size => "100x1" %><br>
</p>
<p>
<h4><%= f.label :body %></h4>
<%= f.text_area :body, :size => "102x10" %><br><br>
</p>
<div class="row">
<div class="col-md-4">
<%= f.radio_button("writer", "Anthony") %>
<%= f.label "Anthony Joseph" %><br>
<%= f.radio_button("writer", "Travis") %>
<%= f.label "Travis Mathis" %><br><br>
</div>
<div class="col-md-4">
<h4 class="center-text">
<%= link_to 'Add', '/categories' %> Category
</h4>
</div>
<%= select_tag(:categories, options_from_collection_for_select(Category.all, :id, :name),:multiple =>true,:size => 8,:class => "text")%>
<%= f.submit :Submit, class: "btn btn-success btn-lg" %>
<% end %>
</div>
</div>
</div>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment