Skip to content

Commit

Permalink
create experiments in seed. fix table field names
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronwiggins committed Jul 9, 2015
1 parent 1925947 commit 64e7089
Show file tree
Hide file tree
Showing 37 changed files with 359 additions and 145 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

ruby '2.2.1'
ruby '2.2.2'
gem 'paperclip'
gem 'aws-sdk', '~> 1.6'
gem 'ratyrate'
Expand Down
16 changes: 8 additions & 8 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ $(function () {
if ($('.experiment').length) {
var material = $('.material').html();

$('.unordered-list-materials').on('click', '.add-material-btn', function (e) {
$('.unorder_numbered-list-materials').on('click', '.add-material-btn', function (e) {
e.preventDefault();
e.stopPropagation();

material = material.replace(/\[[0-9]+\]/g, '[' + $('.unordered-list-materials li').length + ']')
.replace(/_[0-9]+_/g, '_' + $('.unordered-list-materials li').length + '_');
material = material.replace(/\[[0-9]+\]/g, '[' + $('.unorder_numbered-list-materials li').length + ']')
.replace(/_[0-9]+_/g, '_' + $('.unorder_numbered-list-materials li').length + '_');

$('.unordered-list-materials').append('<li>' + material + '</li>')
$('.unorder_numbered-list-materials').append('<li>' + material + '</li>')
})

}
Expand All @@ -58,14 +58,14 @@ $(function () {
if ($('.experiment').length) {
var instruction = $('.instruction-fields').html();

$('.unordered-list-instructions').on('click', '.add-instruction-btn', function (e) {
$('.unorder_numbered-list-instructions').on('click', '.add-instruction-btn', function (e) {
e.preventDefault();
e.stopPropagation();

instruction = instruction.replace(/\[[0-9]+\]/g, '[' + $('.unordered-list-instructions li').length + ']')
.replace(/_[0-9]+_/g, '_' + $('.unordered-list-instructions li').length + '_');
instruction = instruction.replace(/\[[0-9]+\]/g, '[' + $('.unorder_numbered-list-instructions li').length + ']')
.replace(/_[0-9]+_/g, '_' + $('.unorder_numbered-list-instructions li').length + '_');

$('.unordered-list-instructions').append('<li>' + instruction + '</li>')
$('.unorder_numbered-list-instructions').append('<li>' + instruction + '</li>')
})

}
Expand Down
8 changes: 4 additions & 4 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ form {
input {
display: inline-block;
font-family: 'Raleway', sans-serif;
border: 0.1em solid #323232;
border_number: 0.1em solid #323232;
font-size: 1em;
margin: 1em 0.5em;
outline-color: #DFF5D1;
Expand Down Expand Up @@ -118,7 +118,7 @@ a {
.nav-tab, .new-exp {
background-color: #E8E8E8;
color: #333;
border: 0;
border_number: 0;
padding: 0.5em;
font-size: 1em;
font-weight: bold;
Expand Down Expand Up @@ -151,15 +151,15 @@ button {
background-color: #E8E8E8;
font-family: 'Raleway', sans-serif;
color: #333;
border: 0;
border_number: 0;
padding: 0.5em;
}

/* add material */

.new-material {
position: relative;
border: 0.07em solid #323232;
border_number: 0.07em solid #323232;
float: left;
font-size: 1em;
margin: 0;
Expand Down
6 changes: 3 additions & 3 deletions app/assets/stylesheets/experiments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ ul#tabs li {
padding: 5px 20px;
color: #323232;
cursor: pointer;
border-bottom: solid 3px #F2F3F4;
border_number-bottom: solid 3px #F2F3F4;
}
ul#tabs li:hover {
background-color: #E8E8E8;
border-bottom: solid 3px #E8E8E8;
border_number-bottom: solid 3px #E8E8E8;
}
ul#tabs li.active {
border-bottom: solid 3px #323232;
border_number-bottom: solid 3px #323232;
transition: all 0.2s ease-in-out;
}
ul#tab {
Expand Down
6 changes: 3 additions & 3 deletions app/assets/stylesheets/reset.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
border_number: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
Expand All @@ -43,6 +43,6 @@ q:before, q:after {
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
border_number-collapse: collapse;
border_number-spacing: 0;
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/scaffolds.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

#error_explanation {
width: 35em;
border: 0.09em solid #323232;
border_number: 0.09em solid #323232;
padding: 1em;
padding-bottom: 0;
margin-bottom: 20px;
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/experiments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ExperimentsController < ApplicationController
before_filter :authenticate_user!, except: [:index, :show, :vote, :mess_ratings]
before_filter :authenticate_user!, except: [:index, :show, :vote, :mess_ratings, :complete_time_rating]
before_action :set_experiment, only: [:show, :edit, :update, :destroy, :vote]

# GET /experiments
Expand All @@ -9,7 +9,7 @@ def index
end

def mess_ratings
@experiments = Experiment.order_by_mess
@experiments = Experiment.order_number_by_mess
end

def complete_time_rating
Expand Down Expand Up @@ -87,7 +87,7 @@ def set_experiment
def experiment_params
params.require(:experiment).permit(:user_id, :name, :description, :youtube_link, :complete_time, :uploaded_file,
materials_attributes: [:id, :experiment_id, :item],
instructions_attributes: [:id, :experiment_id, :information, :order],
instructions_attributes: [:id, :experiment_id, :information, :order_number],
experiment_votes: [:id, :value, :experiment_id])
end
end
2 changes: 1 addition & 1 deletion app/controllers/instructions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ def set_instruction

# Never trust parameters from the scary internet, only allow the white list through.
def instruction_params
params.require(:instruction).permit(:experiment_id, :information, :order)
params.require(:instruction).permit(:experiment_id, :information, :order_number)
end
end
11 changes: 11 additions & 0 deletions app/models/concept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ class Concept < ActiveRecord::Base
has_many :parents, through: :parent_relationships
has_many :children, through: :child_relationships
end

Concept.create!(name: "Solar")
Concept.create!(name: "Water")
Concept.create!(name: "Evaporation")
ConceptRelationship.create!(parent_id: 1, child_id: 2)
ConceptRelationship.create!(parent_id: 2, child_id: 3)
Concept.first.children
=> "Water" #we expected [["Water"], ["Evaporation"]]
similarly
Concept.fist.parents
=> "Water" #we expected [["Water"], ["Solar"]]
2 changes: 1 addition & 1 deletion app/models/experiment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def votes
read_attribute(:votes) || experiment_votes.sum(:value)
end

def self.order_by_mess
def self.order_number_by_mess
(all.sort_by {|e| e.average("name").nil? ? 0 : e.average("name").avg}).reverse
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/instruction.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Instruction < ActiveRecord::Base
belongs_to :experiment
validates :information, :order, presence: true
validates :information, :order_number, presence: true
validates :information, uniqueness: { scope: :experiment_id }
end
8 changes: 4 additions & 4 deletions app/views/experiments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</li>

<li>
<ul class="unordered-list-materials">
<ul class="unorder_numbered-list-materials">
<%= f.fields_for(:materials) do |ff| %>
<li>
<div class="field material">
Expand All @@ -67,7 +67,7 @@
</li>

<li>
<ul class="unordered-list-instructions">
<ul class="unorder_numbered-list-instructions">
<%= f.fields_for(:instructions) do |ff| %>
<li>
<div class="instruction-fields">
Expand All @@ -76,8 +76,8 @@
<%= ff.text_field :information, :class=> "new-instruction" %>
</div>
<div class="field">
<%= ff.label :order %><br>
<%= ff.number_field :order %>
<%= ff.label :order_number %><br>
<%= ff.number_field :order_number %>
</div>
</div>
</li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/experiments/complete_time_rating.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<% end %>
Instructions<br>
<% experiment.instructions.each do |instruction| %>
<%= instruction.order %> | <%= instruction.information %><br>
<%= instruction.order_number %> | <%= instruction.information %><br>
<% end %><br>
<div class="exp-img">
<% if experiment.uploaded_file_file_name != nil %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/experiments/mess_ratings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<% end %>
Instructions<br>
<% experiment.instructions.each do |instruction| %>
<%= instruction.order %> | <%= instruction.information %><br>
<%= instruction.order_number %> | <%= instruction.information %><br>
<% end %><br>
<div class="exp-img">
<% if experiment.uploaded_file_file_name != nil %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/experiments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Messy Rating : <%= rating_for @experiment, "name", star_path: '/images/ratyrate'
<p>
<strong>Instructions:</strong><br>
<% @experiment.instructions.each do |instruction| %>
<%= instruction.order %> | <%= instruction.information %><br>
<%= instruction.order_number %> | <%= instruction.information %><br>
<% end %>
</p>
<% if @experiment.uploaded_file_file_name != nil %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/instructions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<%= f.text_area :information %>
</div>
<div class="field">
<%= f.label :order %><br>
<%= f.number_field :order %>
<%= f.label :order_number %><br>
<%= f.number_field :order_number %>
</div>
<div class="actions">
<%= f.submit %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/instructions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<tr>
<th>Experiment</th>
<th>Information</th>
<th>Order</th>
<th>order_number</th>
<th colspan="3"></th>
</tr>
</thead>
Expand All @@ -17,7 +17,7 @@
<tr>
<td><%= instruction.experiment_id %></td>
<td><%= instruction.information %></td>
<td><%= instruction.order %></td>
<td><%= instruction.order_number %></td>
<td><%= link_to 'Show', instruction %></td>
<td><%= link_to 'Edit', edit_instruction_path(instruction) %></td>
<td><%= link_to 'Destroy', instruction, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Expand Down
2 changes: 1 addition & 1 deletion app/views/instructions/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
json.array!(@instructions) do |instruction|
json.extract! instruction, :id, :experiment_id, :information, :order
json.extract! instruction, :id, :experiment_id, :information, :order_number
json.url instruction_url(instruction, format: :json)
end
4 changes: 2 additions & 2 deletions app/views/instructions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</p>

<p>
<strong>Order:</strong>
<%= @instruction.order %>
<strong>order_number:</strong>
<%= @instruction.order_number %>
</p>

<%= link_to 'Edit', edit_instruction_path(@instruction) %> |
Expand Down
2 changes: 1 addition & 1 deletion app/views/instructions/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1 +1 @@
json.extract! @instruction, :id, :experiment_id, :information, :order, :created_at, :updated_at
json.extract! @instruction, :id, :experiment_id, :information, :order_number, :created_at, :updated_at
2 changes: 1 addition & 1 deletion bin/spring
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby

# This file loads spring without using Bundler, in order to be fast.
# This file loads spring without using Bundler, in order_number to be fast.
# It gets overwritten when you run the `spring binstub` command.

unless defined?(Spring)
Expand Down
4 changes: 2 additions & 2 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

# Randomize the order test cases are executed.
config.active_support.test_order = :random
# Randomize the order_number test cases are executed.
config.active_support.test_order_number = :random

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
# config.extend_remember_period = false

# Options to be passed to the created cookie. For instance, you can set
# secure: true in order to force SSL only cookies.
# secure: true in order_number to force SSL only cookies.
# config.rememberable_options = {}

# ==> Configuration for :validatable
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

root 'experiments#index'

# The priority is based upon order of creation: first created -> highest priority.
# The priority is based upon order_number of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

# You can have the root of your site routed with "root"
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/20150703152549_create_experiments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ def change
create_table :experiments do |t|
t.integer :user_id
t.text :description
t.text :lesson
t.text :youtube_link
t.float :complete_time
t.string :name
t.integer :age

t.timestamps null: false
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20150703205050_create_instructions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def change
create_table :instructions do |t|
t.integer :experiment_id
t.text :information
t.integer :order
t.integer :order_number

t.timestamps null: false
end
Expand Down
5 changes: 0 additions & 5 deletions db/migrate/20150704040924_add_name_to_experiment.rb

This file was deleted.

5 changes: 0 additions & 5 deletions db/migrate/20150706172648_add_age_to_experiments.rb

This file was deleted.

5 changes: 0 additions & 5 deletions db/migrate/20150708204716_remove_column.rb

This file was deleted.

Loading

0 comments on commit 64e7089

Please sign in to comment.