a component of the Rails framework that holds the state of an object and is responsible for enforcing business rules and persisting the object.
Questions tagged [rails-models]
367 questions
0
votes
1 answer
Rails Complex Query Suggesting Next Object
I have a complex scope on my model giving the user active deals that meet their parameters.
scope :deal_query, lambda { |m, p| where("meal = ? and active = ? and people LIKE '%?%' and inactive_days NOT LIKE '%?%'", m, true, p,…

Kyle C
- 4,077
- 2
- 31
- 34
0
votes
1 answer
Rails 3.2.x render another template view with specific id
I am attempting the follow string of code:
class AppointmentsController < ApplicationController
def create
@appointment = Appointment.new(params[:appointment])
@current_patient = @appointment.patient_id
if @appointment.save
…

sandovalg
- 109
- 13
0
votes
1 answer
Incomplete User Accounts
I'm working on a website where users can make purchases using only their email address, with no account required. If they ever do decide to make an account in the future, all their purchases will get assigned to that account.
So far, I have it so…

skimberk1
- 2,064
- 3
- 21
- 27
0
votes
1 answer
Rails accessing fields stored as JSON data inside a field of a table
I have table Employee with several columns. One of the column is a text field and some data is stored inside it in following format,
:last_working_day => nil,
:first_working_day => ,
:reason_for_leave1 => nil
and so on. Above layout is…

sumitshining
- 159
- 1
- 9
0
votes
1 answer
Ruby on Rails - Need help associating models
Ok, am still a newbie in ruby on rails trying to learn my way around. I have two models (User model and Comment model). Basically a user has a simple profile with an 'about me' section and a photo's section on the same page. Users must be signed in…

Joseph N.
- 2,437
- 1
- 25
- 31
0
votes
2 answers
Rails Format Collection_Select Based on two relationships
I'm trying to figure out how to construct a collection_select to include two relationships. Here are my models:
class Country < ActiveRecord::Base
has_many :companies, :dependent => :destroy
end
class Company < ActiveRecord::Base
belongs_to…

calabi
- 283
- 5
- 18
0
votes
1 answer
Rails - assigning the foreign id at item creation between two related model objects
I am having difficulty successfully assigning the foreign key in a one-to-many relationship at the creation of one of the "many" model objects.
In more concrete terms... I have two models, Course and Section, in which Course has_many :sections, and…

daspianist
- 5,336
- 8
- 50
- 94
0
votes
1 answer
Rails - Dynamic Nested Forms for Only One Element
I've to modals teams and players, and as usual team has many players.
In teams' show page, I'm showing the players and so on. (I've followed railscasts.com/episodes/196-nested-model-form-part-1 tutorial.)
My problem is, when I click on the player's…

CanCeylan
- 2,890
- 8
- 41
- 51
0
votes
2 answers
Working with Constants (in Models)
I am currently working on an app that stores grades in the users table like so (json encoded):
{"6":"6th Grade","7":"7th Grade","8":"8th Grade"}
There are constants setup in the Users Model for each grade span plus one to combine them…

dennismonsewicz
- 25,132
- 33
- 116
- 189
0
votes
2 answers
Ruby on Rails - Counting goals of a team in many matches
I've got a Match model and a Team model.
I want to count how many goals a Team scores during the league (so I have to sum all the scores of that team, in both home_matches and away_matches).
How can I do that? What columns should I put into the…

Kurt Bourbaki
- 11,984
- 6
- 35
- 53
0
votes
1 answer
Multiple images upload carrierwave
I have two models "Posts" and "Images" I wanted "Posts" to have multiple "Images" so I currently have it so "Posts" has many "Images" and "Images" belongs" to "Posts". I have carrierwave taking care of the file upload part, I am wondering if anyone…

Joshua
- 55
- 7
0
votes
2 answers
Duplicate error message when validating a model
How is it possible that the model validation errors messages are getting duplicated in ruby on rails application?

Bogdan Gusiev
- 8,027
- 16
- 61
- 81
0
votes
1 answer
Rails: New entry to a model that belongs_to two other
In my app, a Product has_many opinions, which are written by many clients. Here are models with associations:
class Product < ActiveRecord::Base
attr_accessible :name, :desc, :price
has_many :opinions
end
class Client < ActiveRecord::Base
…

Hassen
- 6,966
- 13
- 45
- 65
0
votes
1 answer
Need to add an alias to a list of results generated by Ruby on rails
Forgive my vague topic, I am currently working on a rails application with three models User, list and items. The user has many lists and a list can have many items. I am currently working on a method that shows the number of lists that a user has…

Abdulrahman Atta
- 92
- 7
0
votes
1 answer
Ruby on Rails, creating CMS with content types
I'm learning RoR nowadays and came up with an idea of creating a very simple content management system. I would like to allow users to create structure of content by adding fields, then the app would create pages to add new items and list all items…

wmiel
- 153
- 5