model

Rails: best way to validate and display error messages for fields not in model

In my Rails 3 application I have a typical 'Email this to a friend' form that has yours/friend's email and name fields. Each of them must be validated and error messages must be displayed, in a fashion similar to ActiveRecord forms: <%= form_tag %> <div class="fields"> <%= label_tag :friends_name %> <%= text_field_tag ...

how can i get the geo_pt on another Model using google app engine(python)

this is my code: class Marker_latlng(db.Model): geo_pt = db.GeoPtProperty() class Marker_info(db.Model): info = db.StringProperty() marker_latlng =db.ReferenceProperty(Marker_latlng) class BaseRequestHandler(webapp.RequestHandler): def render_template(self, filename, template_values={}): values={ } ...

Rails Foreign Key Issue

Sorry if this question seems simple, I am very very new to Rails (just started learning a few days ago), but after consulting Google and "Agile Web Development with Rails" I can't find the answer. I have an issue with Rails 2.3.8 creating a foreign key on two models. My tables look like this: cars manuf...

How to model a schedule in Rails?

Using Ruby on Rails 2.3.8, I'm wondering how to represent a schedule for model that handles "reminders". Examples of reminder: "Must do ABC", Remind me in 3 days "Must do DEF", Remind me in 5 weeks "Must do XYZ", Remind me on 2nd Oct 2010 at 5 pm So, the Must do... goes into a description column. But how to deal with the fact that wh...

When ONE View has ONE ViewModel then a Customer-Order-Product relation/gui can get very nasty...

I think I got some sort of knowledge flash and now I am totally confused. I looked at many mvvm implementations like Ocean,Stuff,BBQShack,MVVM demo,WAF,Chinch1,2 etc... Everyone is doing MVVM differently somehow... There is ONE scenario that drives me nuts. I am missing understanding and I hope someone can clear the clouds in my head. ...

Rails Observer Not Working

Hello, I am trying to use observers in my rails app to create a new entry in my "Events" Model every time a new "Comment" is saved. The comments are saving fine, but the observer is not creating events properly. // comment_observer.rb class CommentObserver < ActiveRecord::Observer observe :comment def after_save(comment) ...

In Rails 2, how would I define a callback method when adding models in a has_many relationship?

In my project I have a Forum that has many Topics, and each Topic has many Posts. When I add a Post to a Topic, I would like to update a timestamp column in the Topic model to record when the last Post was added to the Topic. How can I do this? Thank you for looking! ...

Can You Access Model Data in Controller in CakePHP?

This is probably a dumb question, but I can't find a definitive answer anywhere. Is it possible to access model data in a Controller, and if so, how? I tried the following: $this->set('mydata', $this->Model->find('all', 'conditions' => array('id' => 'someID'))); And accessing it via this in the controller: $mydata['Model']['field'] ...

Don't know how use 'serialize' method in rails

i have a model called user class User < ActiveRecord::Base serialize :friends end when running the console script and create a new object of User class user = User.new user.friends i found a 'NoMethodError' should i write the serialize calling in another file? OR what should i do to make the friends array an attribute for the ...

Partition a large Hibernate model to manage schema dependencies

We are considering splitting our hibernate tables into packages or domains (invoicing, sales, ..etc), primarily for dependency management issues. It doesn't break neatly of course, so we aren't sure how to handle relationships that cross domains. It would be nice to have a new entity annotation for this, but meanwhile one idea is to ma...

Why Isn't This Model Data Loading Into Pages Controller Properly?

I have a Model with data that I want to use to populate a "Recent XYZ" section on the homepage, which is controlled by the Pages controller. In the Pages controller, I have the following code: $this->loadModel('Model'); $this->set('datas', array($this->Model->find('all', array('limit' => 5)))); Then, in Home.ctp, I have tried to acce...

Cakephp - Baking custom models

Hi, I need to bake a large project but a requirement is each model has its schema listed at the top as a multi-line comment. Any ideas ? Thanks, Alex ...

Load models in Zend Framework

I tried to search here before creating this, but I couldn't find anything. I have a simple project without modules and I'd like to load my models (which are inside application/models) without using any namespace and without usign any extra loading lines. Basically what I want to do is to have my class Projects extends Zend_Db_Table_Abs...

How to make state-based model change in QML

Hi, I'm trying to make a QML-based dictionary application. It fetches the word definition via an XML RESTful API and displays them in a ListView. I have it working in this rudimentary mode. But now I'm trying to implement two states for the ListView: standard view with the definitions and a "did you mean" type suggestions list for when t...

How can I compute a conditional sum in my model?

Say I want something like this in Rails: class Proposal < ActiveRecord::Base def interest_level self.yes_votes.count - self.no_votes.count end private def yes_votes self.votes.where(:vote => true) end def no_votes self.votes.where(:vote => false) end end What have I basically done w...

Java pattern question - builder or db code in model?

I need to build a 'MyThingie' using 'A'. MyThingie is in the model package and currently no code in model accesses the DB. My question is which of the following patterns should I use? The top or bottom? Or something completely different. package com.model; public class MyThingie { private String foo = ""; private String bar...

Need help with domain object modeling which contains 100+ fields

There is a class named "Foo" which normally contains more than 100 fields. It's a domain object and I have to customize it for each client because the fields' specification are almost totally different from one client to another (no more than 10 fields are same). Some clients have more than 200 fields. Currently, I have to update the c...

Help with rails association.

Ok guys, so I'm making a scheduler. So I have two tables so far, Shows with "title:string" and "description:text" and I also have ShowTime; with "show_id:integer", "day:string", and "show_time:time". I did the has_many, and belongs_to, I honestly do not know where to go from here on, I want a user to be able to add the times when cr...

Class based default value for field in Django model inheritance hierarchy

How can one accomplish class-based default value in following scheme? I mean, I would like to inherited classes set default value for "number" differently: class OrderDocumentBase(PdfPrintable): number = models.PositiveIntegerField(default=self.create_number()) @classmethod def create_number(cls): raise NotImplement...

Refactoring of model for testing purpose

Hi All, I want to refactor my model so I can properly write a unit test for it. But I have some dependencies. Can anybody point me in the right direction how I can remove these dependencies? class Customer { public function save(array $data, $id = NULL) { // create or update if (empty($id)) { $custom...