ruby-on-rails

Groups in a Gemfile in Rails 3?

In my Gemfile in Rails I have these groups: group :development, :test do gem "capybara" gem "database_cleaner" gem "spork" gem "launchy" end group :bdd do gem "cucumber-rails" gem "rspec-rails" end What does this mean? ...

File does not exist, while using roo in Ruby-on-rails

I am developing a small Ruby-on-rails application. I am using 'roo' gem to open an excel file. But rails throws an IO error while attempting to open the file. It says file does not exist. It works fine in irb. My development machine is windows. Here is my code file ="#{RAILS_ROOT}/public/data/import.xls" file.gsub!("\\","/") workbook =...

Accessing child attributes from parent Factory Girl factories

I'm implementing Factory Girl as a replacement for fixtures in my Rails app. I have several tables that I'm trying to represent using associations. However, to throw a kink into the loop, beyond just defining the associations, I also need to access attributes of the child factories from the parent. Below is an example of what I'm tryi...

capistrano and git problem

Hello I get this error when I do cap deploy:cold. * executing "cd /var/www/myapp.no/releases/20100905130830; rake RAILS_ENV= production db:migrate" servers: ["myapp.no"] [gcrdesign.no] executing command ** [out :: gcrdesign.no] (in /var/www/myapp.no/releases/20100905130830) command finished * executing `deploy:start' [...

In RDBMS, when a relation is one-to-one, does it help if both records point to each other, or is one pointing already enough (no need both pointing)?

I was reading a book and it talks about a User has some more UserDetail, and so the UserDetail will have a user_id pointing back to the Users table. I kind of forgot that, does it help at all to has a field in Users table to have a user_detail_id to point at the UserDetail record? This is so in Ruby on Rails too, that the Users table d...

is it necessary to use db:migrate for working

Is it necessary to use db:migrate? I have existing database, i want to write ROR classes for this and synchronize with DB. How can I do this? ...

Given any Ruby on Rails project folder, can you tell it was Rails 2.3.5 and Ruby 1.8.7 that was used for the project?

So that if you have a Ruby Version Manager, then you can switch to that mode first before altering the project files. (probably best) ...

Rails 3 finding object in a HABTM relationship

Have myself confused . . . I have a SubscriptionPlan ActiveRecord object which has an HABTM to available_to_roles. In Rails 3 I'm trying to create a scope or class method on SubscriptionPlan to get appropriate subscription plans: def self.available_subscription_plans(users_roles) #users_roles = Array of roles #query to find all sub...

How do I vendorize gems for Rails3/Bundler

In Rails 2.X, I could simply copy gems into vendor/gems/gem_name, or use the rake command rake gems:unpack. Since Rails3 uses bundler, it doesn't appear to work anymore. I have found the command bundle package, but it doesn't work the same way. Edit: So, just to elaborate a bit on this: The way that rails 2 worked, I could easily grep...

System architecture, integrating two apps with an API.

I'm having an implementation challenge at the moment, it basically consists of two different rails apps. One rails app (app A) just provides a response in JSON, a record in this case for the nutrition data for one particular food ingredient. The other app (app B) also Rails provides a front-end for users to view ingredients and match t...

Ruby Net::HTTP::Get and JSON responses

I'm trying to connect to an API and retrieve the json results with my rails app, however it doesn't seem to work. Take for example: @request = Net::HTTP::Get.new "http://example.com/?search=thing&format=json" When I try the url in my browser it works! and I get JSON data, however when I try that in Ruby the body is nil. >> y @re...

Simple Admin functionality in Rails 3

Hello, I want to add a admin functionality to my webapp with Rails version 3. I want something very simple, there will be only one admin, this funcionality doesn't need a username field, just a password field. I don't know how to do it, can you help me? Thanks! ...

Products - Categories association. (edit) belongs_to, has_and_belongs_to_many ?

I created a joined table for the purpose. Here's the code: class CreateCategoriesProductsJoin < ActiveRecord::Migration def self.up create_table 'categories_products', :id => false do |t| t.column 'category_id', :integer t.column 'product_id', :integer end end def self.down drop_table 'categories_products'...

Rails 3, how to roll back a Migration file?

Hello, I have the following Rails 3 migration file db\migrate\20100905201547_create_blocks.rb How can I specifically roll back that migration file, allow me to the do: rake db:reset, followed by rake db:migrate? ...

How exactly DO you integrate ckeditor with Paperclip so it can upload image files?

How do you get http://github.com/galetahub/rails-ckeditor working so you can upload image files? I don't think I'll use the s3 storage... any help would be appreciated. ...

Rails 3, help controlling access to a record based on the user id

Hello, I'm a Rails newbie.... Here's what I'm trying to do.... I created a scaffold for notes (t.text :content, t.integer :user_id) What I want to do now is only allow user's to view notes that they created. ie (== user_id) In my /app/controllers/notes_controller.rb I have the following: class NotesController < ApplicationController...

Rails 3 deprecated methods and APIs

Where can one find a list of deprecated methods, APIs, etc, in order to upgrade from Rails 2.x to Rails 3? ...

Is there a better way to write this named_scope? [Rails]

I am using this named_scope to search for products that have a description matching any word the user inputs. E.g., Product.description_like_any("choc pret") Will return products with names like "Chocolate Bar" "Chocolate Covered Pretzels" "Miniature Chocolate Ponies" Here's the named_scope I've written (which works) named_scope :...

How can I prevent the printing of the return value of a closure in Rails?

In a given html.erb file, I have <%= render "steps_list", :post => @post%> In _steps_list.html.erb, I have <%= @post.step_names.each do |step| %> Step: <%= "#{step}" %> <% end %> This works well with one exception. Each step is printed out as I want, but the entire array is also printed out at the end. Step: Rinse Step: Lather...

Rails, Count and Group

I have a table like: +--------+-----------+-------+-----------+ |house_no|house_alpha|flat_no|street_name| +--------+-----------+-------+-----------+ | 1| | |James St | | 1| | |James St | | 1| | |James St | | 2| A| |James St | | ...