Skip to content

Instantly share code, notes, and snippets.

@yurifrl
yurifrl / gist:8278477
Created January 6, 2014 04:56
Function to locate myself
function where_am_i($dir = '.') {
$myDirectory = opendir($dir);
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}
dump($dirArray);
closedir($myDirectory);
}
where_am_i('.');
@yurifrl
yurifrl / Controller.php
Created January 15, 2014 20:45
Find Who called the Method
$trace = debug_backtrace();
if (isset($trace[1])) {
// $trace[0] is ourself
// $trace[1] is our caller
// and so on...
var_dump($trace[1]);
echo "called by {$trace[1]['class']} :: {$trace[1]['function']}";
}
As of 8/25/2013, The following steps will create an ecommerce Rails application using the latest stable version of Spree.
1) cd railsprojects
2) rvm use 1.9.3@spree --create
3) gem install rails -v=3.2.14 --no-ri --no-rdoc
4) rails new mystore -d mysql
5) cd mystore
6) Add the following to the Gemfile
gem 'spree', '2.0.4'
@yurifrl
yurifrl / index.html.erb
Created March 11, 2014 15:55
option type by get
var data = inputs.serializeArray();
var option_types_url = window.location.protocol + "//" + window.location.host + "/" + 'api/option_types?';
$.get(option_types_url, { ids: data[3].value} ).done(function(option_types) {
console.log(option_types_url);
console.log(option_types);
});
@yurifrl
yurifrl / index.html.erb
Created March 11, 2014 17:19
get types from api
var get_types = function() {
var data = inputs.serializeArray();
var option_types_url = window.location.protocol + "//" + window.location.host + "/" + 'api/option_types?';
$.get(option_types_url, { ids: data[3].value} ).done(function(option_types) {
console.log(option_types_url);
console.log(option_types);
});
};
@yurifrl
yurifrl / index.html.erb
Created March 11, 2014 19:57
submit form ajax (not Working)
// Reload types by AJAX POST
$form.submit(function (event) {
event.preventDefault();
var data = $form.serialize();
$.ajax({
type: "POST",
url: form_action,
dataType: "json",
data: data,
success: function (json) {
@yurifrl
yurifrl / index.html.erb
Created March 12, 2014 12:45
ajax update rails
var ids = undefined;
$(document).ready(function () {
var $form = $("form.edit_product");
var form_action = $form.attr("action");
var product_name_id = form_action.split('/')[3];
var option_types_url = window.location.protocol + "//" + window.location.host + "/" + 'api/products/' + product_name_id;
$form.submit(function(e, data){
e.preventDefault();
$.ajax({
<!DOCTYPE html>
<html>
<head>
<title>My Rails App</title>
<%- if protect_against_forgery? -%>
<meta name="authenticity-token" id="authenticity-token" content="<%= form_authenticity_token %>" />
<%- end -%>
<%= javascript_include_tag 'jquery', 'rails' %>
</head>
<body>
@yurifrl
yurifrl / index.html.erb
Created March 12, 2014 14:17
fetch_accordion
var fetch_accordion = function() {
$.getJSON(api_url + 'products/' + product_name_id, null).done(function(json) {
var ids = "";
for (var key in json.option_types) {
ids += json.option_types[key].id + ","
}
$.getJSON(api_url + 'option_types/', {ids: ids} ).done(function(json) {
console.log(json);
});
});
@yurifrl
yurifrl / ajax_upload_spree.js
Created March 12, 2014 19:49
form submit ajax spree rails
var $form = $("form.edit_product");
var form_action = $form.attr("action");
var product_name_id = form_action.split('/')[3];
var api_url = window.location.protocol + "//" + window.location.host + '/api/';
$form.submit(function (e, data) {
e.preventDefault();
$.ajax({
url: form_action,
dataType: "json",
type: "post",