I have the following:
class User < ActiveRecord::Base
has_one :subscription
end
class Subscription < ActiveRecord::Base
belongs_to :user
end
The User has a subscription_id and thus can have only one subscription (which is what I want).
Which works fine, but now I do:
@users = User.find(:all)
and I want all the subscriptions to...
Hi,
I have been searching for a while now for a dead simple CMS with multi-language support. The ideal candidate is very lean and offers the possibility to set up different languages for different domains. It's OK if the language support is provided by a plugin/extension.
For example I want example.com to point to English and example.f...
I have a card-game application which makes use of Single Table Inheritance. I have a class Card, and a database table cards with column type, and a number of subclasses of Card (including class Foo < Card and class Bar < Card, for the sake of argument).
As it happens, Foo is a card from the original printing of the game, while Bar is a ...
Hi!
I'm trying to refactor some code and move some of my before_filter's from the controller to a class.
Before:
class UsersController < ApplicationController
before_filter :find_user
def find_user
@user = User.find(params[:id])
end
end
...
After
class FindUserFilter
def self.filter(controller)
@user = ...
NameError in GenresController#index
uninitialized constant GenresController
RAILS_ROOT: C:/Users/Will/Desktop/INSTAN~1/rails_apps/talewiki
I've created a table called Genres and when I try to connect to it via local host I get the above error.
Any ideas?
...
Ok, I have a generic TimeSlot model that deals with a start_at and an end_at for time spans. A couple models derive from this but I'm referring to one in this question: AppointmentBlock which is a collection of Appointments. I want to validate an AppointmentBlock such that no other AppointmentBlocks have been scheduled for a particular E...
This is how to convert a string to a class in Rails/Ruby:
p = "Post"
Kernel.const_get(p)
eval(p)
p.constantize
But what if I am retrieving a column from an array/active record object like:
Post.description
but it could be
Post.anything
where anything is a string like anything = "description"
How can I make it work? Any ideas. ...
Good morning -
I'm an intermediate-level developer who wants to build on online data-driven app (CRUD with a few calculations and basic HTML form inputs, nothing fancy) that keeps track of user sessions, and looks "professional" (or at least not "homemade").
I'm looking to develop something with the look-and-feel that users get from si...
I have my app configured with Settingslogic, which I love. My question is how to I make a page on my Rails app where Administrators can make changes to the settings specified in config/settings.yml??
I assume said page would have to read and display appropriate form fields for all the values in the YAML file, then save those values back...
I have the following contrived example in Rails. I want to make sure the Garage model has at least one car with this.
class Garage
has_many :cars
validate :at_least_one_car
accepts_nested_attributes_for :cars, :allow_destroy => true
def at_least_one_car
if cars.count == 0
errors.add_to_base("needs at l...
Im new to testing with cucumber and have a question regarding the size of a 'Feature'.
Assume you can add a collection of items to a list and do the usual CRUD , is it preferred to create one feature for this complete set of CRUD actions or a feature for each?
What is the preferred/accepted method ?
At what point does an action become...
Not sure how to frame this question (I'm still wrapping my head around Rails).
Let's try this:
Say I wanted to implement the user side of Ryan Bates' excellent railscast on nested models. (He shows how to implement a survey where you can add and remove questions and answers dynamically). I want the user's side of this: to be able to a...
I just got my rails 2.3.8 app running on ruby 1.9.1. To get into the console, start the webserver, anything that initializes rails, takes 3 - 4 times longer in ruby 1.9 than in ruby 1.8.7. I'm using ruby version managers so I can easily switch between ruby 1.9 and ruby 1.8.7. The speed difference happens in both production and developmen...
I have a VPS with a hosting provider, and recently they decided to upgrade their server hardware and change virtualization software. Since that happened, I've suddenly had a problem with one of my routes in my Rails application. Nothing in my code should have changed (and didn't, as far as I can tell), and all the gems I use (including R...
I'm working with Ruby on rails 2.3.4 and I'd like to pass some parameters from one page to another ones the first one is submitted.
For example:
On the first page, I have a form that when it's filled a Preview button can be clicked to check all the info entered before submitting the form. That button redirects to another page with the ...
Hi,
I'm trying to implement custom dynamic error pages following this post:
http://www.perfectline.co.uk/blog/custom-dynamic-error-pages-in-ruby-on-rails
I did exactly what the blog post says. I included config.action_controller.consider_all_requests_local = false in my environment.rb. But is not working.
My browser shows:
Routing Er...
After listening to Rails Cast No 190 I sat down to try it
So I installed nokogiri with
gem install nokogiri
on my Windows 7 Ultimate laptop. I use Ruby 1.9
and this is the way i Installed Nokogiri
C:\Ruby>gem install nokogiri
Successfully installed nokogiri-1.4.2-x86-mingw32
1 gem installed
Installing ri documentation for nokogiri...
I'm trying to grade a quiz application I would like to make. I have a questions model with and ask(the actual question), 4 choices(a-d), and a correct answer(string).
In the view I have the 4 question being diplayed then the correct answer choice (This is just a test for functionality) and then I created a text_field to accept the use...
Is there some way to change Rails environments mid-way through a test? Or, alternately, what would be the right way to set up a test suite that can start up Rails in one environment, run the first half of my test in it, then restart Rails in another environment to finish the test? The two environments have separate databases.
Some neces...
I'm looking for a solution that will allow my rails app to render a user-friendly maintenance page when there is no Mysql server available to connect to.
Normally a Mysql::Error is thrown from the mysql connection adapter in active_record. Something like:
/!\ FAILSAFE /!\ Wed May 26 11:40:14 -0700 2010
Status: 500 Internal Server Err...