Permalink
Browse files

[DEV] trying railwayjs

  • Loading branch information...
0 parents commit 4bfb9b96076f388878ef7a23db35cd641ea95c66 Elad Meidar committed Nov 15, 2012
@@ -0,0 +1,19 @@
+dump.rdb
+lib-cov
+*.log
+*.csv
+*.out
+*.pid
+pids
+logs
+results
+node_modules
+npm-debug.log
+.idea
+.DS_Store
+log/*.log
+.c9revisions
+coverage.html
+.settings
+doc
+
@@ -0,0 +1 @@
+web: node server.js
@@ -0,0 +1,3 @@
+before('protect from forgery', function () {
+ protectFromForgery('d44d6bbe69ad8dd238640b0bfb402f4161f2226f');
+});
@@ -0,0 +1,80 @@
+load('application');
+
+before(loadSuggestion, {only: ['show', 'edit', 'update', 'destroy']});
+
+action('new', function () {
+ this.title = 'New suggestion';
+ this.suggestion = new Suggestion;
+ render();
+});
+
+action(function create() {
+ Suggestion.create(req.body.Suggestion, function (err, suggestion) {
+ if (err) {
+ flash('error', 'Suggestion can not be created');
+ render('new', {
+ suggestion: suggestion,
+ title: 'New suggestion'
+ });
+ } else {
+ flash('info', 'Suggestion created');
+ redirect(path_to.suggestions());
+ }
+ });
+});
+
+action(function index() {
+ this.title = 'Suggestions index';
+ Suggestion.all(function (err, suggestions) {
+ render({
+ suggestions: suggestions
+ });
+ });
+});
+
+action(function show() {
+ this.title = 'Suggestion show';
+ render();
+});
+
+action(function edit() {
+ this.title = 'Suggestion edit';
+ render();
+});
+
+action(function update() {
+ this.suggestion.updateAttributes(body.Suggestion, function (err) {
+ if (!err) {
+ flash('info', 'Suggestion updated');
+ redirect(path_to.suggestion(this.suggestion));
+ } else {
+ flash('error', 'Suggestion can not be updated');
+ this.title = 'Edit suggestion details';
+ console.log(err);
+ render('edit');
+ }
+ }.bind(this));
+});
+
+action(function destroy() {
+ this.suggestion.destroy(function (error) {
+ if (error) {
+ flash('error', 'Can not destroy suggestion');
+ } else {
+ flash('info', 'Suggestion successfully removed');
+ }
+ send("'" + path_to.suggestions() + "'");
+ });
+});
+
+function loadSuggestion() {
+ Suggestion.find(params.id, function (err, suggestion) {
+ if (err || !suggestion) {
+ redirect(path_to.suggestions());
+ } else {
+ this.suggestion = suggestion;
+ console.log(this.suggestion);
+ next();
+ }
+ }.bind(this));
+}
@@ -0,0 +1,2 @@
+module.exports = {
+};
No changes.
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title><%= title %></title>
+ <%- stylesheet_link_tag('bootstrap', 'style', 'bootstrap-responsive') %>
+ <%- javascript_include_tag('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', 'bootstrap', 'rails', 'application') %>
+ <%- csrf_meta_tag() %>
+ </head>
+ <body>
+ <div class="navbar">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="brand" href="#">Project name</a>
+ </div>
+ </div>
+ </div>
+
+ <div class="container">
+ <% var flash = request.flash('info').pop(); if (flash) { %>
+ <div class="alert alert-info">
+ <a class="close" data-dismiss="alert">×</a>
+ <%- flash %>
+ </div>
+ <% } %>
+
+ <% flash = request.flash('error').pop(); if (flash) { %>
+ <div class="alert alert-error">
+ <a class="close" data-dismiss="alert">×</a>
+ <%- flash %>
+ </div>
+ <% }; %>
+
+ <%- body %>
+
+ <hr />
+ <footer>
+ <p>&copy; Company 2012</p>
+ </footer>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title><%= title %></title>
+ <%- stylesheet_link_tag('bootstrap', 'style', 'bootstrap-responsive') %>
+ <%- javascript_include_tag('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', 'bootstrap', 'rails', 'application') %>
+ <%- csrf_meta_tag() %>
+ </head>
+ <body>
+ <div class="navbar">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="brand" href="#">Project name</a>
+ </div>
+ </div>
+ </div>
+
+ <div class="container">
+ <% var flash = request.flash('info').pop(); if (flash) { %>
+ <div class="alert alert-info">
+ <a class="close" data-dismiss="alert">×</a>
+ <%- flash %>
+ </div>
+ <% } %>
+
+ <% flash = request.flash('error').pop(); if (flash) { %>
+ <div class="alert alert-error">
+ <a class="close" data-dismiss="alert">×</a>
+ <%- flash %>
+ </div>
+ <% }; %>
+
+ <%- body %>
+
+ <hr />
+ <footer>
+ <p>&copy; Company 2012</p>
+ </footer>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,31 @@
+<%- errorMessagesFor(suggestion) %>
+<div class="control-group">
+ <%- form.label("content", false, {class: "control-label"}) %>
+ <div class="controls">
+ <%- form.textarea("content") %>
+ </div>
+</div>
+<div class="control-group">
+ <%- form.label("status", false, {class: "control-label"}) %>
+ <div class="controls">
+ <%- form.input("status") %>
+ </div>
+</div>
+<div class="control-group">
+ <%- form.label("category_id", false, {class: "control-label"}) %>
+ <div class="controls">
+ <%- form.input("category_id") %>
+ </div>
+</div>
+<div class="control-group">
+ <%- form.label("user_id", false, {class: "control-label"}) %>
+ <div class="controls">
+ <%- form.input("user_id") %>
+ </div>
+</div>
+<div class="control-group">
+ <%- form.label("viewd", false, {class: "control-label"}) %>
+ <div class="controls">
+ <%- form.checkbox("viewd") %>
+ </div>
+</div>
@@ -0,0 +1,9 @@
+<div class="page-header"><h1>Edit suggestion</h1></div>
+
+<% form_for(suggestion, {action: path_to.suggestion(suggestion), method: 'PUT', id: "suggestion_form", class: 'form-horizontal'}, function (form) { %>
+ <%- partial('suggestions/form.ejs', {locals: {form: form, suggestion: suggestion}}) %>
+ <div class="form-actions">
+ <%- form.submit('<i class="icon-ok icon-white"></i> Update suggestion', {class: 'btn btn-primary'}) %> or
+ <%- link_to('Cancel', path_to.suggestion(suggestion), {class: 'btn'}) %>
+ </div>
+<% });%>
@@ -0,0 +1,39 @@
+<div class="page-header">
+ <h1>Index of suggestion</h1>
+</div>
+
+<div class="row">
+ <div class="span12">
+ <p><%- link_to('<i class="icon-plus icon-white"></i> New suggestion', path_to.new_suggestion(), {class: 'btn btn-primary'}) %></>
+ </div>
+</div>
+
+<div class="row">
+ <div class="span12">
+ <% if (suggestions.length > 0) { %>
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th>ID</th>
+ <th>Actions</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% suggestions.forEach(function (suggestion) { %>
+ <tr>
+ <td><strong><%- link_to('suggestion #' + suggestion.id, path_to.suggestion(suggestion)) %></strong></td>
+ <td>
+ <%- link_to('<i class="icon-edit"></i> Edit', path_to.edit_suggestion(suggestion), {class: 'btn btn-mini'}) %>
+ <%- link_to('<i class="icon-remove icon-white"></i> Delete', path_to.suggestion(suggestion), {class: 'btn btn-mini btn-danger', method: 'delete', remote: true, jsonp: '(function (u) {location.href = u;})'}) %>
+ </td>
+ </tr>
+ <% }); %>
+ </tbody>
+ </table>
+ <% } else { %>
+ <p class="alert alert-block alert-info">
+ <strong>No suggestions were found.</strong>
+ </p>
+ <% } %>
+ </div>
+</div>
@@ -0,0 +1,11 @@
+<div class="page-header">
+ <h1>New suggestion</h1>
+</div>
+
+<% form_for(suggestion, {action: path_to.suggestions(), method: 'POST', id: "suggestion_form", class: 'form-horizontal'}, function (form) { %>
+ <%- partial('suggestions/form.ejs', {locals: {form: form, suggestion: suggestion}}) %>
+ <div class="form-actions">
+ <%- form.submit('<i class="icon-ok icon-white"></i> Create suggestion', {class: 'btn btn-primary'}) %> or
+ <%- link_to('Cancel', path_to.suggestions(), {class: 'btn'}) %>
+ </div>
+<% });%>
@@ -0,0 +1,19 @@
+<div class="page-header">
+ <h1>Details of suggestion</h1>
+</div>
+
+
+<table class="table table-bordered">
+ <tbody>
+ <tr><th>content</th><td><%= suggestion.content %></td></tr>
+ <tr><th>status</th><td><%= suggestion.status %></td></tr>
+ <tr><th>user_id</th><td><%= suggestion.user_id %></td></tr>
+ </tbody>
+</table>
+
+<div class="well">
+ <%- link_to('<i class="icon-edit icon-white"></i> Edit', path_to.edit_suggestion(suggestion), {class: 'btn btn-primary'}) %>
+ <%- link_to('<i class="icon-remove icon-white"></i> Delete', path_to.suggestion(suggestion), {class: 'btn btn-danger', method: 'delete', remote: true, jsonp: '(function (u) { location.href = u; })'}) %>
+ or
+ <%- link_to('Back to index', path_to.suggestions()) %>
+</div>
@@ -0,0 +1,15 @@
+{ "development":
+ {
+ "driver": "mysql",
+ "host": "localhost",
+ "port": 3306,
+ "username": "root",
+ "database": "fiverr_dev"
+ }
+, "test":
+ { "driver": "memory"
+ }
+, "production":
+ { "driver": "memory"
+ }
+}
@@ -0,0 +1,17 @@
+var express = require('express');
+
+app.configure(function(){
+ var cwd = process.cwd();
+
+ app.use(express.static(cwd + '/public', {maxAge: 86400000}));
+ app.set('view engine', 'ejs');
+ app.set('view options', {complexNames: true});
+ app.set('jsDirectory', '/javascripts/');
+ app.set('cssDirectory', '/stylesheets/');
+ app.use(express.bodyParser());
+ app.use(express.cookieParser('secret'));
+ app.use(express.session({secret: 'secret'}));
+ app.use(express.methodOverride());
+ app.use(app.router);
+});
+
@@ -0,0 +1,9 @@
+app.configure('development', function () {
+ app.disable('view cache');
+ app.disable('model cache');
+ app.disable('eval cache');
+ app.enable('log actions');
+ app.enable('env info');
+ app.use(require('express').errorHandler({ dumpExceptions: true, showStack: true }));
+});
+
@@ -0,0 +1,11 @@
+app.configure('production', function () {
+ app.enable('view cache');
+ app.enable('model cache');
+ app.enable('eval cache');
+ app.enable('merge javascripts');
+ app.enable('merge stylesheets');
+ app.disable('assets timestamps');
+ app.use(require('express').errorHandler());
+ app.settings.quiet = true;
+});
+
@@ -0,0 +1,8 @@
+app.configure('test', function(){
+ app.use(require('express').errorHandler({ dumpExceptions: true, showStack: true }));
+ app.settings.quiet = true;
+ app.enable('view cache');
+ app.enable('model cache');
+ app.enable('eval cache');
+});
+
Oops, something went wrong.

0 comments on commit 4bfb9b9

Please sign in to comment.