Hi All,
I have around 40 models in my RoR application. I want to setup a after_save callback for all models. One way is to add it to all models. Since this callback has the same code to run, is there a way to define it globally once so that it gets invoked for all models.
I tried this with no luck:
class ActiveRecord::Base
after_s...
I this model:
class Bunny < ActiveRecord::Base
attr_accessor :number
validates_presence_of :number
validates_numericality_of :number
end
Whenever I submit a form to create this model I get the following error:
undefined method `number_before_type_cast' for #<Bunny:0x103624338>
...
Hello. I'm diving into RoR and plan to build a few websites. Alongside the websites, I'd like to use RoR to build a simple RESTful game server API that can be used to orchestrate a two-player iOS game that I'm writing. The game is puzzle-based time challenge (the first player to solve the puzzle wins) and the players will only be comm...
I want to store two models using active record, but delete doesn't work as expected.
Evaluation has id, name and description
and SqlEvaluation has additional two columns of query_string and database.
I want to use those two tables, and eval_typ_id is used to distinguish which subclass should be used: 1 for SqlEvaluation.
create tabl...
I've been applying has and belongs to many style associations to a project I've been working on, but because I wanted to capture extra information in my join model, I'm implicitly setting it up via the more elaborate belongs_to/has_many approach instead of has_and_belongs_to_many. After initially stumbling on this, I learned that I neede...
I am trying to change all of the default_standing fields to FALSE for all other records when someone marks one as TRUE. That way I will only ever have one default record in the table. Here is what I am doing in both create and update in my controller, but it doesn't seem to be working:
def update
@standing = Standing.find(params[:...
How does one create a Rails migration properly so that a table gets changed to MyISAM in MySQL? It is currently InnoDB. Running a raw execute statement will change the table, but it won't update db/schema.rb, so when the table is recreated in a testing environment, it goes back to InnoDB and my fulltext searches fail.
How do I go about ...
I need lightweight database for an ASP.NET MVC application.
would prefer not to install anything additional on the host box
would also prefer being a little more robust than XML
would like to use activerecord or entity frameworks
...
I have a form which i'd like to simplify. I'm recording a startdate and an enddate, but would like to show the user only a startdate and then a drop down with number of days.
But I'm having problems with my model and storing it correctly.
The first part works.
def date=(thedate)
#puts the startdate in the correct format...
...
This question on SO appears to be related to my question, but I'm not sure my question is answered by that.
An address can belong to more than one model (UserProfile and Event)
What's the correct way to implement this?
The basic tables:
user_profiles(id)
events(id)
Options for implementing the addresses table:
addresses(id,user_pro...
In a stats part of a Rails app, I have some custom SQL calls that are called with ActiveRecord::Base.execute() from the model code. They return various aggregates.
Some of these (identical) queries are run in a loop in the controller, and it seems that they aren't cached by the ActiveRecord query cache.
Is there any way to cache custom...
I have a ShowRating model which keeps a log of every show rated on by a user and have been keeping an average rating and ratings count cached inside my Show model, so I can access it in the show controller without rebuilding this data on the fly. I've been keeping an eye on the SQL queries executed and I'm curious about why Rails chose t...
I'm fairly new to rails, working on a Rails 3 app with a Profile model for users.
In the profile Model I'd like to have a "name" entry, and I'd like to be able to access logical variations of it using simple syntax like:
user.profile.name = "John Doe"
user.profile.name.first = "John"
user.profile.name.last = "Doe"
Is this possible, o...
Hello. I'm quite new to ActiveRecord and i got handed an old project where the customer want some updates done. It's an event signup system.
The system have the following classes;
Registration (holds address information etc for a registration)
Event (the event to which participants sign up)
Participants (people who've signed up to the ev...
Hi,
I have the following SQL generated from my Rails app, it is trying to get a list of all auto models that have live adverts in a marketplace app & from mysql:
SELECT `models`.* FROM `models`
INNER JOIN `autos` ON autos.model_id = models.id
INNER JOIN `ads` ON `ads`.id = `autos`.ad_id
WHERE (ads.ad_status_id = 4 AND pub_start_...
I'm using a simple ajax toggle partial in a view, to allow a user to toggle a message as read vs. unread. When I toggle I get a failure.
MessagesController#show could not find MessageCopy without an ID.
Application trace: messages_controller.rb:21 in 'show' (first line of the action)
show.html.erb
<%= render :partial => "read_unread_...
I'm using basic scaffold structure. What I need, is to add 'moderate' action and view by changing published to true. In my idea, on moderate.html I should get the list of all unpublished entries with the ability to change and save their parameters.
Here are parts of my code:
#names_controller.rb
def moderate
@name = Name.find(:all, :...
I'm working on a social networking application and am trying to build
a complex query that efficiently pulls all of a users' friends'
checkins from the database. Basically I need: "user.friends.checkins"
I've recreated (in simplified form) the data structure below for
reference and included several solutions I've found, however I feel
...
I am using Devise with Rails and ActiveRecord. I have a User model with some base information. I also created 2 other descendants to that: Patient and Doctor. My problem is ActiveRecord is not creating new rows at this moment, and I can't figure out what is wrong. It creates rows on other tables of the db, but I don't understand why it's...
Hi, I'm creating an application that'll display a random picture based upon a defined letter in a word.
Images are attached to a Pictures model (containing another "letter" field) using Paperclip, and will be iterated through in an each block.
How would I go about passing the letter back from the each block to the model for random sele...