ruby-on-rails

rails 3 - app design question - models and controllers

Hello, I am building small app that will only display products in various categories. And will never display categories without products. So far I have two models - product and category and wondering if I really need controller dedicated to category model? I can only see one advantage so far - rendering collection (partial) of category. ...

I can't find a method to save the values in a hash directly in rails

I'm a newbie to rails, and I have researched a whole day. I think my problem is easy. There is a table questions_tags_relation, it has two columns(no id): columns: question_id -> string tag_id -> string And I have a hash: record = {:question_id=>'111111', :tag_id=>'22222'} And there is no model 'QuestionsTags', and I don't want to...

Passing association parameters on ActiveRecord object creation

In my application I have 2 classes like this: class City < ActiveRecord::Base has_many :events end class Event < ActiveRecord::Base belongs_to :city attr_accessible :title, :city_id end If I create city object: city = City.create!(:name => 'My city') and then pass parameters to create event like this: event = Event.create!...

Ruby command line MVC framework?

I'm looking to write an app for the shell, *nix mostly. And I'm currently in love with Ruby, especially the 'rails way'. So if there was a framework that applied rails like concepts to the commandline in ruby then that would be really fantastic. I'v allready looked into SimpleCommand and Hirb, nothing quite what I was looking for. To ...

How to create a model without primary key in rails

I want to create a model 'Relation' which extends ActiveRecord::Base, set it's table name as 'questions_tags', and without primary key. What should I do? class Relation < ActiveRecord::Base set_table_name 'questions_tags' # set table name, right? # how to define 'no-pk'? end UPDATE Hi, guys. I know use 'create_table' can solv...

email css ruby help

hi all I am pulling emails into my ruby on rails web app and displaying them from users to see and reply etc within my app. Problem is the emails css when displaying the email effects my sites css and visa versa. Any one know the best solutition to the problem ? Can use an iframe i suppost but dont think secure ? cheers Rick ...

Rails 3 and Sunspot, rdoc or good tuto

I'm new to sunspot and rails 3, so I followed this little tuto: http://github.com/exempla/sunspot But there is not a lot of details, and the official github of outoftime/sunspot do not speak much about the rails 3 version. ex: How can I do a rake sunspot:reindex So if anyone know where I can find some good rdoc for the rails 3 versio...

Can't Execute Ruby Script/Server

Hi, I am new to ruby. I've just installed Ruby and Rails on my fresh Ubuntu OS. I created a new rails project based on the screencast from rubyonrail websites. http://media.rubyonrails.org/video/rails_blog_2.mov However, when executing ruby script/server, I am getting this error: Missing the Rails gem. Please gem install -v= ra...

Why are ruby processes at 100% CPU on passenger

I have a rails app (2.3.5) running on a VPS with 4 cores @ 2 GHz and 4GB memory. I am running nginx (0.7.61) and phusion passenger(2.2.14) on Ruby Enterprise (1.8.7-2010.01) with the max pool size set at 30. My problem is that it seems as if every ruby process that is executing a rails request runs at near 100% cpu. If I run TOP they ...

Find parents without or with children in polymorphic associations in rails

I have two models: cars and pictures in my RoR project class Car < ActiveRecord::Base has_many :pictures, :as => :imageable, :dependent => :destroy end and class Picture < ActiveRecord::Base belongs_to :imageable, :polymorphic => true, :dependent => :destroy end How I can find all cars only with child pictures? ...

Why would you upload assets directly to S3?

I have seen quite a few code samples/plugins that promote uploading assets directly to S3. For example, if you have a user object with an avatar, the file upload field would load directly to S3. The only way I see this being possible is if the user object is already created in the database and your S3 bucket + path is something like ...

Routes only want a show on default despite explicit member statement

When I go to .. www.website.com/admin/organizations/org_deals , I get : Missing template admin/organizations/show.erb in view path My routes.rb : map.namespace :admin do |admin| admin.napespace :organizations do |organization| organization.org_deals 'org_deals', :action => 'org_deals', :member => {org_deals => :get} end end ...

Are there any ways of speeding up rake?

For me, no matter what rake task has been executed, it's at least 20 seconds. The time is too long. My OS: windows xp, rails: 2.3.8, ruby: 1.8.7 UPDATE Are there any ways of speeding up rake? Someone said upgrade to ruby 1.9, but I don't know does it work well with rails 2.3.8? (I see in the rails' website, they recommend ruby 1.8.7...

There is no real 'prepared statement' in rails?

When we use ActiveRecord, we can use: User.find(:first, :conditions=>["name=?", name]) It looks like ActiveRecord are using 'prepared statement', but after looking into the code, I found ActiveRecord just use String.dup and connection.quote() to adjust the content to build a sql, not like Java. So, there is no real prepared statment ...

Rails Multi Model 'Primary Key' Validation

Hello, I have three models, say Item, Category, Label. Item can have one Category and many Labels, however each Item record must have a unique combination of Category and/or Labels. I'm using Rails 2.3.5, what is the best way to ensure this integrity? Thanks! ...

Rails Polymorphic Many-to-Many

The application I'm working on is going to allow for the import of contacts from a variety of services. It will be possible to send invitations to these contacts. These contacts can then come to the site and sign up to become users. In order to avoid the validations and other such nonsense that is placed on my user model, I have created...

resque , redis and rails 2.3.8

Hi anyone can give me idea what i need to install to setup resque and redis on my rails 2.3.8 application. I have installed. gem install redis gem install redis-namespace gem install resque gem install json after that i have tried to run rake task from my application. C:\test>rake redis:install (in C:/cyncabc) rake aborted! Don't ...

Rails - Failing Routes in deployment

I have an app that has the following in the routes file: namespace "admin" do # ADMINISTRATIVE ROUTES ONLY root :to => 'home#index' resources :comments do member do get :approve get :reject end end resources :users do member do get :block get :unblock ...

rake fails with "Virtual timer expired"

The following is my environment: OS X 10.5 Xcode 3.1.4 rvm 0.1.38 ruby 1.8.9-p399 (via rvm) rails 2.3.8 I started getting this error when rake tries to run my tests: bash$ rake Virtual timer expired bash$ # End of output! And with tracing enabled: bash$ rake --trace ** Invoke default (first_time) ** Invoke test (first_time) ** E...

Mongoid Twitter-style following, can't specify criteria/conditions for relationship array

I'm at my wit's end trying to handle these errors. Basically, I've created the following User and Relationship patterns, using Mongoid to handle my database. This seems like a near-carbon copy of the example at the bottom of the page here. I'm trying to call any of the following: user1.relationships.find(:all, :conditions => {:rel_us...