datamapper

nested forms for 2 models in rails using dm-accepts_nested_attributes and dm-is-tree

≯℡__Kan透↙ 提交于 2019-12-06 08:39:48
I have two models: Post and Image in a forum application where Posts are arranged in parent-child format using dm-is-tree. Up this point, the images had been part of the Post model. As the Post model gets unwieldy and I need to add more depth to notating the image, I'm working to spin off the Image into its own model, but is still part of the post in output. So I started integrating dm-accepts_nested_attributes in a simple arrangement: class Post include DataMapper::Resource property :id, Serial property :istop, String property :created_at, DateTime property :updated_at, DateTime property

How to extend DataMapper::Resource with custom method

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 08:22:49
问题 I have following code: module DataMapper module Resource @@page_size = 25 attr_accessor :current_page attr_accessor :next_page attr_accessor :prev_page def first_page? @prev_page end def last_page? @next_page end def self.paginate(page) if(page && page.to_i > 0) @current_page = page.to_i - 1 else @current_page = 0 end entites = self.all(:offset => @current_page * @@page_size, :limit => @@page_size + 1) if @current_page > 0 @prev_page = @current_page end if entites.size == @@page_size + 1

ruby resque without loading rails environment

≡放荡痞女 提交于 2019-12-06 08:06:45
问题 I have a resque worker which works great but is just too slow. The main reason for this is I'm using activerecord and having to load the entire environment which takes at least 10-20 seconds just to load up (I don't keep a running worker at all times as I'm using Heroku and pay for the time the worker runs). I'm using a resque worker to grab & parse data from an external website and then dumping the data into my database. My question is whether I should rewrite the method to not use Rails and

Simple Search With Datamapper and Sinatra

南笙酒味 提交于 2019-12-06 07:16:51
问题 I'm fairly new to Ruby and backend development in general. That being said I'm trying to create a simple search form. I'm using Sinatra as the framework and Datamapper as my ORM. What is the best way to do this? Below is my schema I would like the search action to search both the tile and category. require 'sinatra' require 'datamapper' DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/cal.db") class Event include DataMapper::Resource property :id, Serial property :title, String property :text

Use DataMapper instead of ActiveRecord [closed]

ⅰ亾dé卋堺 提交于 2019-12-06 03:45:49
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . DataMapper idea is definitely better than ActiveRecord. It has one API for a variety of data stores, including RDBMS and NoSQL stores.

How to handle multidimensional output with (nested) lists using the Zend\\Db\\TableGateway with a mapper in Zend Framework 2?

烈酒焚心 提交于 2019-12-05 22:53:46
I'm developing a RESTful ZF2 based application and using a TableGateway implementation (subclass of the Zend\Db\TableGateway ) in combination with a simple mapper for the model, similar to the Album example of the ZF2 manual . Table class <?php namespace Courses\Model; use ... class CourseTable { protected $tableGateway; public function __construct(TableGateway $tableGateway) { $this->tableGateway = $tableGateway; } public function findOnceByID($id) { $select = new Select(); $where = new Where(); $select->columns(array( 'id', 'title', 'details', )); $select->from($this->tableGateway->getTable(

Heroku and Datamapper problems

一笑奈何 提交于 2019-12-05 21:19:27
I can launch a basic app on Heroku, displaying a message with get '/'... works just fine. However, whenever I try to add sqlite with datamapper, the thing breaks down. In order to see my app structure, check out the project on github . I've kept the code pretty bare-bones. In the log from heroku I'm getting: 2011-06-26T21:28:36+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/adapters.rb:163:in `require': no such file to load -- dm-postgres-adapter (LoadError) The thing about this is that I'm not using postgres, so I'm confused why it is saying this. "The thing

DataMapper: Create new record or update existing

随声附和 提交于 2019-12-05 10:30:37
Does DataMapper provide a convenient way to create a new record when none exists or update an existing one? I couldn't find anything in the API documentation. This is what I have at the moment which doesn't seem very elegant: foo = Foo.get(id) if foo.nil? foo = Foo.create(#attributes...) else foo.update(#attributes...) end foo.save Foo.first_or_create(:id=>id).update(attributes) or (Foo.get(id) || Foo.new).update(attributes) I just try Foo.first_or_create(:id=>id).update(attributes) but it gets wrong sometimes, so I find some tips from here: DataMapper Docs Now I make my code works like: Foo

error happens when I try “all” method in datamapper

☆樱花仙子☆ 提交于 2019-12-05 09:11:24
When I try to do this in Sinatra, class Comment include DataMapper::Resource property :id, Serial property :body, Text property :created_at, DateTime end get '/show' do comment = Comment.all @comment.each do |comment| "#{comment.body}" end end It returns this error, ERROR: undefined method `bytesize' for #<Comment:0x13a2248> Could anyone point me to the right direction? Thanks, Luke Antins Your getting this error because Sinatra takes the return value of a route and converts it into a string before trying to display it to the client. I suggest you use a view/template to achieve your goal: #

Displaying Error Message with Sinatra

◇◆丶佛笑我妖孽 提交于 2019-12-05 05:36:53
I'm writing a simple app that takes standard input from the user. As for the email entry, I have it verify if it is in a standard email format and then have it list the problems like this when a new instance is going to be saved: u = User.new u.email = params[:email] u.save if u.save redirect '/' else u.errors.each do |e| puts e end end I know that if it is correct it should return back to the home page. If it is wrong I want it to return to the home page as well, but I want it to return an error value (so I can have a pop-up or just something onscreen letting the user know that the format of