Commit a30ab6ec authored by Sara Kuqi's avatar Sara Kuqi
Browse files

user_id to results

parent b02e3996
......@@ -18,7 +18,7 @@ class ResultsController < ApplicationController
def create
@result = Result.new(result_params)
#@result.user_id = current_user.id
respond_to do |format|
if @result.save
format.html { redirect_to @result, notice: 'Result was successfully created.' }
......@@ -32,8 +32,8 @@ class ResultsController < ApplicationController
def update
@result = Result.find(result_params[:result_id])
#result = current_user.id
@result.row_order_position = result_params[:row_order_position]
respond_to do |format|
if @result.update(result_params)
format.html { redirect_to @result, notice: 'Result was successfully updated.' }
......@@ -64,7 +64,7 @@ class ResultsController < ApplicationController
end
def result_params
params.require(:result).permit(:sample_id, :user_id, :measurement, :name)
params.fetch(:result, {})
params.require(:result).permit(:sample_id, :user_id, :measurement, :name, :element_C,:element_H,:element_N,:element_S)
params.fetch(:result, {}).merge {user_id: current_user.id}
end
end
......@@ -2,7 +2,7 @@ class UsersController < ApplicationController
before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
before_action :correct_user, only: [:index, :show, :edit, :update]
before_action :set_type
before_action :admin_user, only: [:destroy, :edit]
before_action :admin_user, only: [:destroy]
def index
......@@ -68,12 +68,10 @@ class UsersController < ApplicationController
user = User.find(params[:id])
if user.type == "Chemist"
user.type = "Operator"
user.save
elsif user.type == "Operator"
user.type = "Chemist"
user.save
end
#user.save
user.save
flash[:success] = "Type changed"
redirect_to users_url
end
......@@ -113,6 +111,4 @@ class UsersController < ApplicationController
redirect_to(root_url) unless current_user.admin?
end
end
......@@ -65,7 +65,4 @@ class Sample < ApplicationRecord
assign_attributes(calculation: @expected_result)
end
def deliver
sleep 10
end
end
......@@ -5,7 +5,7 @@ class User < ApplicationRecord
self.inheritance_column = :type
attr_accessor :remember_token, :activation_token, :reset_token
default_scope { order(updated_at: :desc) }
before_save { self.email = email.downcase }
before_create :create_activation_digest
validates :name, presence: true, length: { maximum: 50 }
......
<footer class="container-fluid text-center">
<p style="text-align:left">© 2016 - mol_app</p>
<small><p style="text-align:left">© 2016 - mol_app</p></small>
</footer>
......@@ -28,7 +28,7 @@ Rails.application.routes.draw do
resources :samples, only: [:create, :destroy, :show, :edit, :update]
resources :password_resets, only: [:new, :create, :edit, :update]
resources :microposts, only: [:create, :destroy]
resources :results, only: [:create, :destroy, :show, :edit, :update]
resources :samples do
member do
......
class AddUserIdToResults < ActiveRecord::Migration[5.0]
def change
add_column :results, :user_id, :integer
add_reference :results, :user, foreign_key: true
end
end
class AddIndexToResults < ActiveRecord::Migration[5.0]
def change
add_index :results, [:user_id, :created_at]
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161205091941) do
ActiveRecord::Schema.define(version: 20161207091726) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -50,6 +50,8 @@ ActiveRecord::Schema.define(version: 20161205091941) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.index ["user_id", "created_at"], name: "index_results_on_user_id_and_created_at", using: :btree
t.index ["user_id"], name: "index_results_on_user_id", using: :btree
end
create_table "samples", force: :cascade do |t|
......@@ -82,4 +84,5 @@ ActiveRecord::Schema.define(version: 20161205091941) do
end
add_foreign_key "microposts", "users"
add_foreign_key "results", "users"
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment