ruby-on-rails

Roles that are User<>Project Based

Hello... Currently I'm using Devise & CanCan which allows me to create Users with Roles using a (Roles_Users) table. That's nice, but what I want is to Have Projects in my app and for each project for a user to possibly have a role like (Admin, Viewer, etc) IE, roles are not assigned to users but to users based on what projects the...

Redis: weird protocol/network errors

I'm running Redis and connecting from Ruby using ezmobius's Redis gem[1]. Periodically (about once a day) I get a series of exceptions in my Rails app caused by Redis returning strange results. They are often triggered by an exception such at this: Redis::ProtocolError: Protocol error, got '3' as initial reply byte ...

Rails 3 Server Startup problem with fastercsv

I have a rails 2.3.5 app getting upgraded to Rails 3. I did every thing I am required to do for upgrading and when I start the rails server using rails server it gives me this Please switch to Ruby 1.9's standard CSV library. It's FasterCSV plus support for Ruby 1.9's m17n encoding engine. I am using ruby-1.9.2-p0 and have faster...

ImageMagick conflict on Ubuntu running webbrick

Hi all I am trying to install refinerycms, a Ruby on Rails CMS on Ubuntu 10.04 LTS. I run rails server and I get the following exception: carcher@carcher-laptop:~/Code/tgc$ rails server => Booting WEBrick => Rails 3.0.0 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Ex...

How do I install all the gems from my environment.rb (Rails 2)

I tried rake gems:install but I get No such file or directory - /Users/macuser/Sites/hq_channel/config/database.yml I bet the default is set wrong. What file do I need to change? And where do I find what to change it to? ...

Assigning value to serialized attribute causes SerializationTypeMismatch

I find it surprising that this has not been asked yet, so I am hoping I am doing something fundamentally wrong and help will arrive soon. I have this create_table "foo", :force => true do |t| t.text "bar", :null => false ... end class Foo < AR::Base serialize :bar, Bar end class Bar de...

Rails 3 - How to get the row number from a model with an order by

Hi, I am putting together a small app that has a leaderboard concept in it. Basically, the model is just a player_name and a current_score. what I want to do is get the ranking of a specific player, and given that new scores are coming in all the time, it needs to be dynamic. Obviously I could just do a normal find with an order by cl...

insert line into file using rails templates

I am trying to create a rails template that will add code to files at particular line numbers. For example I need to add a route to the config/routes.rb I have tried sed, gsed(only cause I am on a mac and they say that sed has problems with insert and append), anyway, I was not able to achieve the result I want. Any help on this will b...

workling client stops in a few seconds after start

Hi I'm trying to use RabbitMQ instead of Starling I've configured my app and everything seems to be fine but when i run 'script/ workling_client start' it starts to work and ends in a few seconds and I can't get why My app works perfectly with Starling I'm using Fedora 13 ruby 1.8.7 rails 2.3.8 mongrel(configured according to http://gi...

Optional parameters for Rails Image Helper

In my current Rails (Rails 2.3.5, Ruby 1.8.7) app, if I would like to be able to define a helper like: def product_image_tag(product, size=nil) html = '' pi = product.product_images.first.filename pi = "products/#{pi}" pa = product.product_images.first.alt_text if pi.nil? || pi.empty? html = image_tag("http...

How to show validation errors from an associated model in Rails?

I have 3 models: User, Swatch + Color. A user has many swatches, and a swatch references a color. Users create swatches on their profile page (users/show/id). The color model handles validation through the swatch model with accepts_nested_attributes_for :color and validates_associated :color. My question is, how to show the color-spec...

Rails/Active Record FAILSAFE error "User can't be referred"

Using Rails 2.3.2 (not in a good situation to upgrade at the moment) with ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]. Getting the following error when trying to save when doing validations on the model, if the validations are :on => :update. If I change the validations to :on => :create and create a new record, I don't...

Threaded Comments are not working for me.

Hello, my website has the ability for users to post top level comments successfully, but I am having much trouble with comment children. I am using polymorphic associations, so the comment model can apply to Articles, Profiles, and Pictures. In each of the three cases, the comment will see the model as "commentable". I want to create a ...

Understanding Ruby Syntax

Possible Duplicates: What is the best way to learn Ruby? Explain Iterator Syntax on Ruby on Rails I'm still learning ruby, ruby on rails and such. I'm getting better at understanding all the ruby and rails syntax but this one has me a little stumped. respond_to do |format| format.html # index.html.erb format.xml { rend...

Server returning no response for certain URLs for Rails app on Apache2

I just implemented a new controller in Rails, and added routing info to routes.rb. Things work fine when I access the new URL on my local machine in dev mode. However, after pushing the changes onto my prod server and attempting to navigate to the URLs controlled by the new controller, I get no response from the server. I've tried restar...

How can you get a sql script of changes from Rails migrations (for MySQL)?

I've seen http://github.com/muness/migration_sql_generator, but it doesn't work properly with MySQL for certain important operations. Is there any other way we can capture the sql generated during a rails migration? The reason I'm asking is that I cannot run the migrations on the production server since it is maintained by technical sup...

AWS::S3::NoConnectionEstablished error using aws-s3 gem in Rails

I am getting a AWS::S3::NoConnectionEstablished exception when trying to download a file using paperclip + s3. I can fire up s3sh and create a connection just fine with the s3 credentials in my config. What is the best next step I can take to debug this issue? This is what my model looks like: has_attached_file :file, ...

how to use action names in rails3 routing with match

I've got a path of http://localhost:3000/recipes/1/ingredient/3 In my routes, I define match "/recipes/:recipe_id/ingredients/:id" => "ingredients#show" However, I don't think I should be defining each action in my routes file, I shouldn't have a seperate entry for 'ingredients#show' than another for 'ingredients#edit'. How do I ...

How do I pull heroku data into a local SQLite3 database? Running into problems

I'm trying to make a local backup of the data from my Rails app, which is deployed to Heroku, and running into problems. I followed the instructions here: http://docs.heroku.com/taps and installed Taps. I get two types of errors. I created a SQLite db locally and tried pulling data with this command: (sudo) heroku db:pull sqlite://...

Globally Reuse ActiveRecord Queries across Models?

Not sure how to word the question concisely :). I have say 20 Posts per page, and each Post has 3-5 tags. If I show all the tags in the sidebar (Tag.all.each...), then is there any way to have a call to post.tags not query the database and just use the tags found from Tag.all? class Post < ActiveRecord::Base end class Tag < ActiveRe...