ruby-on-rails

Problem with role requirement and restful authentication

Our site uses role requirement and restful authentication plugins for rails. We are seeing most users able to access the site (login) just fine but a handful of logins are failing after being successfully authenticated and forwarded to the member's controller. It seems like the require roles line isn't finding the appropriate role and ...

Do I need to have a "references" column in both my Question and Answer models?

If I have a has_many and belongs_to relationship between Questions and Answers: class Question < ActiveRecord::Base has_many :answers end class Answer < ActiveRecord::Base belongs_to :question end Do I also need to modify the migration files to use "references": class CreateAnswers < ActiveRecord::Migration def self.up cre...

Proper arguments for initializing a model in a view?

My question template lists answers, and lets somone add a new answer for a question. But I'm not sure where and how to initialize a new answer for this line: <%= link_to 'New answer', new_question_answer_path(@question, Answer.new) %> from the context below: <p> <b>Body:</b> <%=h @question.body %> </p> <h1>Listing answers</h1> ...

Delegate pattern for Rails remote database?

I am working on a Rails application that requires roles-based permissions (let's call it the "Hidden" application), but the application will not be handling user authentication. The Main application sets an encrypted cookie and the Hidden application uses that as evidence of authentication. The Hidden application needs to implement a v...

Changing a Rails route based on deployment type

Is there a good way of modifying a route based on the deployment type? Basically, I have a route that has a :requirements => {:protocol => "https"}, and I'd like that to only happen in production, but not in development. ...

rails number_to_currency bug?

Hi, I have a rails app (rails version 2.1.0) and today I found a very weird error. A money value(mysql decimal column with precision 8 and scale 2) is 86.02. However, number_to_currency method returns "$86.20". This happens only in production server. My dev server returns correctly. The production server is red hat and dev is ubuntu. ...

Rails asset_host prefixes are showing up in every URL

I've got Rails configured to use assets0-3 as described here: AssetTagHelper So, in the production environment we have this bit of code: config.action_controller.asset_host = "http://assets%d.example.com" Now, assets0-3 is showing up at random in all sorts of URLs created using only the link_to helpers. ...

With nested routes does the parent controller or the child controller process the request for the "new" action?

If you have a nested resource defined like this: map.resources :magazines, :has_many => :ads. for these models: class Magazine < ActiveRecord::Base has_many :ads end class Ad < ActiveRecord::Base belongs_to :magazine end When you invoke this url: /magazines/1/ads/1/new with the nested route helper: new_magazine_ad_pa...

How do I disable cache_money caching for certain ActiveRecord models

I tried doing the def index(*args); end; trick within the models I'd like cache_money to ignore, but to no avail. ...

Rails 2.3.4 and jquery form plugin works on development, not in production?

Hello, i'm trying to build a contact form in Rails 2.3.4. I'm using the jQuery Form plugin along with this (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) for validations. Everything works in my development environment (mac os x snow leopard), the loading gif appears and on my log the email gets sent and the "request co...

Core dump equivalent for the Rails exception

So I got an exception log from my application. I have a call stack, request parameters and all other usual stuff in that log. This is a rare exception and info from the log doesn't contain all details I need to resolve / duplicate the problem. I wonder if there is some way (gem?) to get full dump of Rails application state in case of a...

AssociationTypeMismatch problem when saving data

in a previous question i was stumped.. but stack overflow provided the solution my two models class Team < ActiveRecord::Base has_many :fixtures, :finder_sql => 'SELECT * FROM fixtures where (home_team = #{id} or away_team = #{id})' has_many :home_fixtures, :class_name => "Fixtures", :foreign_key => :home_team has_many :away_fixt...

Rails' ActiveRecord serialize :attr method gives "Missing Class or module error"

Hi there, I'm trying to serialize a simple attribute in an ActiveRecord model, and Rails 2.3.4 doesn't like it. class Shopper serialize :tags end >> a = Shopper.new => <#Shopper...> >>a.tags = ['aoeu','stnh'] => ['aoeu','snth'] >> a.save => TypeError: class or module required anyone know what I'm missing? ...

Netbeans doesn't recognize ruby gems installed using Terminal

I have installed a GEM called "Ziya" using the terminal in Mac OSx. However, when I open the application using the Netbeans, it says that the GEM cannot be found. If I install Ziya using the GEM manager, I get the following error and the GEM doesn't get installed, WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and ...

Necessary steps for using a gem (e.g. json) in Ruby on Rails app?

I'm having trouble getting rubygems to work in my Rails app. Specifically, I'm trying to use the json gem, documented here: http://flori.github.com/json/ I can successfully use JSON.parse() in IRB and script/console but not in my rails app. I know it's some combination of config.gem 'json' in environment.rb and other things, but can't...

Trouble Running Cucumber with Stephen Celis config app

I'm trying to get cucumber up and running with a config app I use in Rails. The config app is used to set various config options in Rails, for example the site value for ActiveResource: self.site = "http://#{App['domain']}#{App['path']}" When I run "cucumber features", I can get an error bad URI(absolute but no path): http:// (URI::...

How do I define ActiveRecord relationships between two models that relate to each other in two different ways?

In my app I have the classes User, Video, and Vote. Users and Videos can relate to each other in two different ways: as a one-to-many or as a many-to-many. The former is when a User submits a Video (one user can submit many videos). The latter is when a user votes on a video (users have many videos through votes, and vice versa). H...

Should I be putting html input tags in my view?

I'm new to rails, and was wondering if I should be putting code like the second line inside my view: <%= text_field_tag 'new_ingredient' %> <input type=button ID="btnAddIngredient" Value="Add" onclick="addIngredient();" /> or is there a helper I should be using to generate the tag instead? I know about the form and tag helpers, but I ...

ruby-on-rails: getting database unique id

I have a simple model, Post with title and content. I'm trying to link Post & Users together by the post unique_id and the user unique_id In the course of my testing I've noticed that object_id is not the unique id of the record in the database. It changes with every page refresh. My schema does not explicitly state the need for a un...

Naming Boolean columns in Rails

Let's say I have a Dog and I want to store if it is trained in Rails. Conventionally, Ruby methods that return booleans have names that end with ?. Should I call the database column trained?, or should I call the database column trained and have a method class Dog def trained? trained end end The latter option seems inefficien...