天道酬勤,学无止境

sinatra

Retrieve records which have many-to-many association, using ruby and datamapper

问题 我正在学习 Sinatra,我已经阅读了 datamapper 文档并找到了这个 n 到 n 关系示例: class Photo include DataMapper::Resource property :id, Serial has n, :taggings has n, :tags, :through => :taggings end class Tag include DataMapper::Resource property :id, Serial has n, :taggings has n, :photos, :through => :taggings end class Tagging include DataMapper::Resource belongs_to :tag, :key => true belongs_to :photo, :key => true end 我从上面的代码中了解到,一张照片可能有许多或零个标签,而一个标签可能有许多或零个照片。 如何检索已加载与其关联的标签的照片列表。 我知道 datamapper 使用惰性方法,因此它不会自动加载关联的类(在本例中为 photo.tag)。 所以这: photos = Photo.all 将产生一个带有不带标签的 Photo 对象的数组。 有没有办法自动检索它,还是我必须遍历数组并手动设置?

2022-05-12 05:41:23    分类:技术分享    ruby   sinatra   datamapper

Upload videos to Amazon S3 using ruby with sinatra

问题 I am building an android app which has a backend written on ruby/sinatra. The data from the android app is coming in the form of json data. The database being used is mongodb. I am able to catch the data on the backend. Now what I want to do is to upload a video on Amazon S3 being sent from the android app in the form of byte array. I also want to store the video in a form of a string in the local database. I have been using carrierwave, fog and carrierwave-mongoid gems but didn't have any luck. These are the some blogs I followed: https://blog.engineyard.com/2011/a-gentle-introduction-to

2022-05-08 06:10:03    分类:技术分享    ruby   amazon-s3   sinatra   carrierwave   fog

node-webkit equivalent for sinatra?

问题 我一直在考虑学习如何基于 web 技术制作简单的 Mac OS X 应用程序,我遇到了 node-webkit,它看起来很有吸引力。 但是,我最近投资学习了 Sinatra/Ruby 的基础知识,我想继续学习该课程。 对于使用 Sinatra 的开发人员,是否有“node-webkit 等价物”? 或者,有没有推荐的方法来使用 Sinatra 框架(或 Ruby)来构建本质上是 Web 包装器的 OS X 应用程序? 回答1 Sinatra 是一个服务器端框架。 与客户端的 Node-webkit 相反。 如果您需要与服务器交互,您仍然可以在您的服务器上使用 sinatra(以及 node.js、php...)。 但是如果你在 node.js 上寻找像 sinatra 这样的框架,你应该看看 Express.js:https://npmjs.org/package/express 回答2 Node-webkit 可以使用file或http ,使用哪种取决于您的需要。 大多数时候你不需要,Node-webkit 完全在客户端运行,只使用 HTML、javascript 和 css。 您当然可以在加载 Node-webkit 时初始化本地网络服务器,但首先尝试制作一个基本的“Hello World”应用程序来了解它是如何工作的。 如果您仍然认为需要启动 Web 服务器

2022-05-06 19:43:14    分类:技术分享    ruby   webkit   sinatra   chromium   node-webkit

Rails: How do I require NumberHelper and make it work?

问题 我正在尝试编写一个简单的 Sinatra 东西,但我需要动作包中的 ActionView::Helpers::NumberHelper。 http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html 问题是,我该如何安装和使用它? irb(main):001:0> require 'action_view/helpers/number_helper' irb(main):002:0> number_with_precision(1) NoMethodError: undefined method `number_with_precision' for main:Object irb(main):004:0> ActionView::Helpers::NumberHelper.number_with_precision(1) NoMethodError: undefined method `number_with_precision' for ActionView::Helpers::NumberHelper:Module 为什么这个简单的步骤不起作用? 此外,如果我需要所有的废话: irb(main):001:0> require 'action_pack' irb(main):004:0>

2022-05-05 10:10:17    分类:技术分享    ruby   sinatra   actionpack

RestKit - Post object and update its attributes

I have a small app using RestKit with a Sinatra-backed server. When I post a user object to the server, the server successfully saves the user and responds with a json representation of the newly created user. Here's the code to create a user on the client: User *currentUser = [User currentUser]; currentUser.email = @"jacob@mail.com"; currentUser.firstName = @"Jacob"; currentUser.lastName = @"Morris"; currentUser.phone = @"2088956709"; currentUser.deviceId = @"MY-DEVICE-ID"; currentUser.password = @"password"; currentUser.passwordConfirmation = @"password"; currentUser.timeStamp = [NSNumber

2022-04-29 22:14:05    分类:问答    objective-c   ios   sinatra   restkit

Retrieve records which have many-to-many association, using ruby and datamapper

I'm learning Sinatra, and I have read datamapper documentation and found this n to n relationship example: class Photo include DataMapper::Resource property :id, Serial has n, :taggings has n, :tags, :through => :taggings end class Tag include DataMapper::Resource property :id, Serial has n, :taggings has n, :photos, :through => :taggings end class Tagging include DataMapper::Resource belongs_to :tag, :key => true belongs_to :photo, :key => true end What I understood from the code above is that one photo may have many or zero tags, and a tag may have many or zero photos. How do I retrieve a

2022-04-29 15:17:56    分类:问答    ruby   sinatra   datamapper

Sinatra - ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base

I've only been able to find rails answers to this question. Whenever I run rake db:migrate I am getting the aforementioned error. As far as I am aware, I have setup everything correctly so have no idea what's wrong. config/environment.rb ENV['SINATRA_ENV'] ||= "development" require 'bundler/setup' Bundler.require(:default, ENV['SINATRA_ENV']) configure :develpoment do set :database, 'sqlite3:db/database.db' end require './app' Rakefile require "./config/environment" require "sinatra/activerecord/rake"

2022-04-29 09:22:19    分类:问答    ruby   activerecord   sinatra   sinatra-activerecord

Upload videos to Amazon S3 using ruby with sinatra

I am building an android app which has a backend written on ruby/sinatra. The data from the android app is coming in the form of json data. The database being used is mongodb. I am able to catch the data on the backend. Now what I want to do is to upload a video on Amazon S3 being sent from the android app in the form of byte array. I also want to store the video in a form of a string in the local database. I have been using carrierwave, fog and carrierwave-mongoid gems but didn't have any luck. These are the some blogs I followed: https://blog.engineyard.com/2011/a-gentle-introduction-to

2022-04-28 20:45:28    分类:问答    ruby   amazon-s3   sinatra   carrierwave   fog

node-webkit equivalent for sinatra?

I've been thinking about learning how to make simple Mac OS X applications based on web-technology and I came across node-webkit which seems compelling. However, I've recently invested in learning the basics of Sinatra/Ruby and I wanted to stay on that course. Is there a "node-webkit equivalent" for developers who use Sinatra? Or, is there a recommended way to use the Sinatra framework (or Ruby) to build OS X apps that are essentially web wrappers?

2022-04-27 14:52:42    分类:问答    ruby   webkit   sinatra   chromium   node-webkit

CTRL+C won't stop a sinatra app

Normally when I run a rails app from the console during development I can just press Ctrl + C and it exits. Then I can run the app again, thus bouncing it and effecting changes. I am running a sinatra app. I just run the ruby file. $: ruby myapp.rb When I press Ctrl+C, however, it won't stop the app. I've had to bring up the Ubuntu System Monitor and kill the Ruby process. Very annoying. Anyone seen this/dealt with this before?

2022-04-27 14:37:48    分类:问答    ruby   console   sinatra