Questions tagged [rails-models]

a component of the Rails framework that holds the state of an object and is responsible for enforcing business rules and persisting the object.

367 questions
3
votes
1 answer

in Rails, with check_box_tag, how do I keep the checkboxes checked after submitting query?

Ok, I know this is for the Saas course and people have been asking questions related to that as well but i've spent a lot of time trying and reading and I'm stuck. First of all, When you have a model called Movie, is it better to use Ratings as a…
user866503
3
votes
3 answers

Loading large data sets into a Rails application

I'm dealing with millions of rows of data that I want to load into my Rails application as Models. I'm using MySQL as a database, and I'm on Rails 2.3.14. One of my co-workers says that it's inadvisable to add records directly to MySQL, bypassing…
Ben G
  • 26,091
  • 34
  • 103
  • 170
2
votes
1 answer

Simplify the code in models

I have 3 models and polymorphic relationships. Post: #models/post.rb class Post < ActiveRecord::Base after_create :create_vote has_one :vote, :dependent => :destroy, :as => :votable protected def create_vote self.vote =…
Mike
  • 1,042
  • 1
  • 8
  • 14
2
votes
1 answer

Rails Multi Table Inheritance and Polymorphic Associations

I'm currently developing an application using Rails 3.2 and have run into a bit of a problem. I know this has been asked hundreds of times before but I couldn't find an answer that solved it. Here is a similar ER:…
ollym
  • 21
  • 1
2
votes
3 answers

should a non-database data class I need be created as a Rails 3 "model", or just a basic class in the /lib area?

should a non-database data class I need be created as a Rails 3 "model", or just a basic class in the /lib area? I want to build some classes to represent calculated domain objects. So the fields won't reference a database table/column. There will…
Greg
  • 34,042
  • 79
  • 253
  • 454
2
votes
1 answer

uninitialized constant User::relationship using @blog.user.followers.build

The below code works without error: = form_for @blog.comments.build, :remote => true do |f| However the below results in the error "uninitialized constant User::relationship": = form_for @blog.user.followers.build do |f| User model is declared…
Jonathan Maddison
  • 1,067
  • 2
  • 11
  • 24
2
votes
0 answers

rails associations -- can I use :through multiple times?

Can I do something like this? Class School < ActiveRecord::Base has_many :courses has_many :students, :through => courses, :through => coursesections, :through => enrollments end Class Course < ActiveRecord::Base has_many :coursesections …
Deonomo
  • 1,583
  • 3
  • 16
  • 25
2
votes
1 answer

CouchRest Model use a custom value instead of guid for _id field

I wonder if there is a way to use a custom string value (e.g. name of the object) as the _id field instead of a guid in CouchRest Model. E.g. class Cat < CouchRest::Model::Base property :name end By default, it will use a guid as _id field. But…
PokerIncome.com
  • 1,708
  • 2
  • 19
  • 30
2
votes
3 answers

I'm gettgin No route matches {:action=>"new", :controller=>"posts"} even though it's not in my routes.rb file. HELP?

OK so this is my first question posted to stackoverflow. I'm pretty new to coding, been learning Ruby on Rails for the past 3 months. There could be a few things wrong with my code but here it goes. Basically I'm trying to get a User to Post. I'm…
abhi
  • 139
  • 1
  • 7
2
votes
1 answer

Create a model that is related to 2 other models using Rails

I have models like that: class Person has_many :groups has_many :group_memberships, :foreign_key => "member_id" end class Group_Membership belongs_to :member, :class_name => 'Person' belongs_to :group end class Group belongs_to :person has_many…
Zeroz
  • 125
  • 1
  • 8
2
votes
1 answer

Rails, string or integer values in status-column in db

I'm having an event-model that has a status attribute, and wonder if I should make it into a string or integer field. The event can have three different statuses, "gathering", "active" or "closed". If I should go with the integer solution, should I…
jonepatr
  • 7,769
  • 7
  • 30
  • 53
2
votes
2 answers

Validation on model with 'intentional' invalid data

The data source I am working with is terrible. Some places where you would expect integers, you get "Three". In the phone number field, you may get "the phone # is xxx". Some fields are simply blank. This is OK, as I'm parsing each field so "Three"…
Richter
  • 627
  • 6
  • 13
2
votes
3 answers

Get all records that exist in both the tables

Below are two tables with some sample data :- Uploads: id: 1 , file_ref:abc id: 2, file_ref: abc1 id: 4, file_ref: abc3 id: 5, file_ref: abc4 id: 6, file_ref: abc5 id: 7, file_ref: abc6 media: id: 3, name: 'My Doc' , type: doc id:…
2
votes
1 answer

login devise teacher model using TeacherID while student model using email

Is it possible to allow one devise model login on basis of the username or some other unique id while other one using default devise email authentication process.
2
votes
2 answers

Conditional Statements In Ruby on Rails Model File

Is it possible for us to write conditional statements in our Rails model file for example in my case if I want to implement some validations based on if a user is singned_in or not in my Customer.rb file. if user_signed_in? // if signed_in is true …