Skip to content

Commit

Permalink
Well this is what actually works, even made Rubocop happy
Browse files Browse the repository at this point in the history
  • Loading branch information
paresharma committed Mar 23, 2015
1 parent 82bfe6c commit a622645
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 9 additions & 4 deletions app/assets/javascripts/scorm_rte/rte.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ function LMSAPI(){
console.log(this.cache);

var url = 'http://localhost:3000/scorm_rte/stores/fetch?sco_instance_id='+this.SCOInstanceID;
console.log(url);
$.getJSON( url, function( data ) {
this.cache = data
var tempCache = {};

$.ajax({
url: url,
dataType: 'json',
async: false
}).done(function( data ) {
tempCache = data;
});

// this.cache = JSON.parse(localStorage.getItem('k')) || {}

this.cache = tempCache;
console.log(this.cache);
console.log('***');
return "true";
Expand Down
9 changes: 6 additions & 3 deletions app/controllers/scorm_rte/stores_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ module ScormRte
class StoresController < ApplicationController
def fetch
store = Store.find_by(sco_instance_id: params[:sco_instance_id])
render json: (store.data||{}).to_json
render json: (store.data || {}.to_json)
end

def create
store = Store.find_or_initialize_by(sco_instance_id: params[:scorm_rte_store][:sco_instance_id])
store.data = params[:scorm_rte_store][:data]
store = Store.find_or_initialize_by(
sco_instance_id: params[:scorm_rte_store][:sco_instance_id]
)

store.data = params[:scorm_rte_store][:data].to_json
store.save

render nothing: true
Expand Down

0 comments on commit a622645

Please sign in to comment.