Skip to content
Snippets Groups Projects
Commit f6221ce4 authored by Felipe Bombardelli's avatar Felipe Bombardelli
Browse files

Add controller and vies of subjects and update the his repository for the same...

Add controller and vies of subjects and update the his repository for the same standard of learning object and institution
parent 51d59521
No related branches found
No related tags found
No related merge requests found
class SubjectsController < ApplicationController
# GET /subjects
# GET /subjects.json
def index
@subjects = subject_repository.all
end
# GET /subjects/1
# GET /subjects/1.json
def show
@subject = subject_repository.find("##{params[:id]}")
end
private
def subject_repository
repository.for(:subject)
end
# Never trust parameters from the scary internet, only allow the white list through.
def subject_params
params[:subject_object]
end
end
module OrientDb
class SubjectRepository < Base
include OrientDb::Methods::EdgeMethods
def find_all
connection.query "SELECT FROM Subject", limit: -1
# Example:
# list = repository.for(:subjects).all
# list.each do |subject|
# subject_object.inspect <LearningObject model>
# end
def all
hash = connection.query "SELECT FROM Subject"
subjects = build_subjects(hash)
end
def find_by_id(id)
connection.query "SELECT FROM Subject where @rid = '#{id}'"
# Usage:
# subject = repository.for(:subjects).get_by_dspace_id 123
#
def find(id)
result = connection.query "SELECT FROM #{id}"
build_subject result.first
end
def destroy_data(id)
return @connection.command "DELETE VERTEX Subject where @rid = '#{id}'"
rescue
return nil
def create(name, url)
connection.command sprintf("INSERT INTO Subject (name) VALUES ('%s')", name)
end
def get_objects(id)
connection.query "select expand(in('IsAbout')) from #{id}"
# Usage:
# repository.for(:subjects).destroy subject
#
def destroy(subject)
connection.command sprintf("DELETE VERTEX %s", subject.id)
end
def update(id,operation,atributte,new)
puts "update #{id} #{operation} #{atributte} = #{new}"
return @connection.command "update #{id} #{operation} #{atributte} = #{new}"
private
def build_subject(args={})
return Subject.new(
:id => args["@rid"],
:name => args["name"],
)
end
def build_subjects(hash=[])
subjects = []
hash.each do |h|
subjects << build_subject(h)
end
return subjects
end
end
end
<p id="notice"><%= notice %></p>
<h1>Listing Subject</h1>
<%for subject in @subjects%>
<%= render 'shared/application/object_vertical', object: subject %>
<%end%>
<h1><%= @subject.name %></h1>
......@@ -25,7 +25,8 @@ Rails.application.routes.draw do
post '/learning_objects/:id/like' => 'learning_objects#like', as: 'like_learning_object'
resources :institutions
get 'subjects/', to: 'subjects#index'
get 'subjects/:id', to: 'subjects#show'
get '/faq' => 'welcome#faq'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment