Skip to content

Commit

Permalink
tags for design methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cearto committed Jul 24, 2014
1 parent e5ab73a commit c2db8e1
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class TagsController < InheritedResources::Base
def create
@tag = Tag.new(params[:tag])


if @tag.save
# format.html { redirect_to @tag, notice: 'Design method was successfully created.' }
# format.json { render json: @tag, status: :created, location: @tag }
render :json => {:tag => tagify(@tag.content, {:removable => true})}
else
format.html { render action: "new" }
format.json { render json: @tag.errors, status: :unprocessable_entity }
end

end
def tagify(id, content, options)
tag = "<span class='tag-label label-gap'>#{content} "
if options[:removable]
tag = tag + '<span onclick="removeTag('+ (id.to_s) +', this);" class="glyphicon glyphicon-remove-circle"></span>'
end
tag = tag + '</span>'
tag.html_safe
end
end
7 changes: 7 additions & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Tag < ActiveRecord::Base
attr_accessible :design_method_id, :case_study_id, :discussion_id, :user_id, :content
# belongs_to :design_method
# belongs_to :case_study
# belongs_to :discussion
# belongs_to :user
end
37 changes: 37 additions & 0 deletions app/views/tags/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%= form_for(@tag) do |f| %>
<% if @tag.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tag.errors.count, "error") %> prohibited this tag from being saved:</h2>

<ul>
<% @tag.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :design_method_id %><br>
<%= f.number_field :design_method_id %>
</div>
<div class="field">
<%= f.label :case_study_id %><br>
<%= f.number_field :case_study_id %>
</div>
<div class="field">
<%= f.label :discussion_id %><br>
<%= f.number_field :discussion_id %>
</div>
<div class="field">
<%= f.label :user_id %><br>
<%= f.number_field :user_id %>
</div>
<div class="field">
<%= f.label :content %><br>
<%= f.text_field :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/tags/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing tag</h1>

<%= render 'form' %>

<%= link_to 'Show', @tag %> |
<%= link_to 'Back', tags_path %>
35 changes: 35 additions & 0 deletions app/views/tags/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<h1>Listing tags</h1>

<table>
<thead>
<tr>
<th>Design method</th>
<th>Case study</th>
<th>Discussion</th>
<th>User</th>
<th>Content</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

<tbody>
<% @tags.each do |tag| %>
<tr>
<td><%= tag.design_method_id %></td>
<td><%= tag.case_study_id %></td>
<td><%= tag.discussion_id %></td>
<td><%= tag.user_id %></td>
<td><%= tag.content %></td>
<td><%= link_to 'Show', tag %></td>
<td><%= link_to 'Edit', edit_tag_path(tag) %></td>
<td><%= link_to 'Destroy', tag, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Tag', new_tag_path %>
5 changes: 5 additions & 0 deletions app/views/tags/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New tag</h1>

<%= render 'form' %>

<%= link_to 'Back', tags_path %>
29 changes: 29 additions & 0 deletions app/views/tags/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Design method:</strong>
<%= @tag.design_method_id %>
</p>

<p>
<strong>Case study:</strong>
<%= @tag.case_study_id %>
</p>

<p>
<strong>Discussion:</strong>
<%= @tag.discussion_id %>
</p>

<p>
<strong>User:</strong>
<%= @tag.user_id %>
</p>

<p>
<strong>Content:</strong>
<%= @tag.content %>
</p>

<%= link_to 'Edit', edit_tag_path(@tag) %> |
<%= link_to 'Back', tags_path %>
13 changes: 13 additions & 0 deletions db/migrate/20140724015008_create_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateTags < ActiveRecord::Migration
def change
create_table :tags do |t|
t.integer :design_method_id
t.integer :case_study_id
t.integer :discussion_id
t.integer :user_id
t.string :content

t.timestamps
end
end
end
Binary file added public/no-image-available.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c2db8e1

Please sign in to comment.