ruby-on-rails3

Best Practice Mongoid:NestedResources

Hello Mongo Friends, I'm starting off with a small Rails3:MongoDB:Mongoid project and came along some questions that's nature is more architectural. When to use nested resources, and how deep to nest? I'm not a friend of nested routes at all, but they become handy if not stacked deeper than 2 resources and document oriented database...

Rails 3 - no such file to load -- openssl

Hello, when running a Rails server, I get the following error: no such file to load -- openssl I try a solution I find online. I go to ~/.rvm/src/ruby-1.9.2-head/ext/openssl. I type : ruby extconf.rb, but I get the following: === OpenSSL for Ruby configurator === === Checking for system dependent stuff... === checking for t_open() in -...

What's the way to translate model attributes in rails with mongoid?

I've problem with mongoid and model translations. When I'm trying use mongoDB on my model I haven't idea to translate attributes and model name. It's normally in *.yml files but in this time this doesn't work. Any ideas? ...

rails-3.0.0rc with jquery as default

In a new rail 3 app I want to replace prototype with jquery, but my initializer script: module ActionView::Helpers::AssetTagHelper remove_const :JAVASCRIPT_DEFAULT_SOURCES JAVASCRIPT_DEFAULT_SOURCES = %w(jquery-1.4.1.min rails) reset_javascript_include_default end won't work any more. I get: constant ActionView::Helpers::AssetT...

Rails 3.0.0rc - ActiveRecord::Base.class_name

In a Rail 3 project I have a script: <%= javascript_tag do -%> var columns = new Array(); <% for table in @tables -%> <% for column in ActiveRecord::Base.const_get(ActiveRecord::Base.class_name(table)).columns -%> columns.push(new Array('<%= table %>', '<%= column.name %>')); <% end -%> <% end -%> function mergeTab...

Updating several model instances at the same time, The Rails Way?

I have a settings table with two fields, key and value. Now, while creating an administration section for it I want to be able to edit all settings at once. Is there a "Rails (3) way" to do this that will save me some time? ...

Rails 3.0 Engine - Execute code in ActionController

Hello all, I am upgrading my Rails plugin to be an engine that works with the latest 3.0RC1 release and I'm having a bit of trouble figuring out the best (and most correct) way to extend ActionController. I've seen this post by DHH and this question here on SO, but my question is more about how to properly call code within the ActionCon...

Easy Ruby data table/search question

Hello, So I have a table that looks like this: A B A C B A C A C B I want to delete the lines that the connection of two values are already in represented (so A----B is the equivalent connection as B----A). Basically I want my table to look like this. A B A C B C How can I do this in Ruby? -Bobby EDIT: H...

Rails 3 : `require` within a generator

I am writing a Rails 3 generator, but things get a bit complicated so I would like to extract some code to put it in a separate file. So I create a file in the generator folder, and within my generator file, I put at the top: require 'relative/path/to/my/code.rb' But when I launch the generator, it tells me that it can't find the fil...

Can I install Ruby on Rails 2.x and Ruby on Rails 3 side by side

Hi, I have a Ubuntu rails enviroment for playing around with ROR. Right now I am running Rails 2.3.8. I want to look into rails 3. Is it possible to run both dev enviroments side-by-side? If not, how do I clean up my rails 2.x system to install rails 3? Or do I need to setup a whole new Ubuntu machine? Any help, links... pointers wou...

appending to rake db:seed in rails and running it without duplicating data

Rake db:seed populates your db with default database values for an app right? So what if you already have a seed and you need to add to it(you add a new feature that requires the seed). In my experience, when I ran rake db:seed again, it added the existing content already so existing content became double. What I need is to add some see...

Preventing HTML character entities in locale files from getting munged by Rails3 xss protection

We're building an app, our first using Rails 3, and we're having to build I18n in from the outset. Being perfectionists, we want real typography to be used in our views: dashes, curled quotes, ellipses et al. This means in our locales/xx.yml files we have two choices: Use real UTF-8 characters inline. Should work, but hard to type, a...

How do you render hashes as JSON in Rails 3

I have found how to render ActiveRecord objects in Rails 3, however I cannot figure out how to render any custom objects. I am writing an app without ActiveRecord. I tried doing something this: class AppController < ApplicationController respond_to :json ... def start app.start format.json { render :json => {'ok'=>true}...

How to get an array with column names of a table

I need an array with the column names of a table Any ideas how I can do this with rails 3.0.0rc? ...

Phusion Passenger spawning problems

I am working with a Rails 3RC app and using Phusion Passenger for the first time. It takes about 30 seconds to start up the app on the first request and here is the typical memory consumption for each ruby process in my app: PID     VMSize     Private   Name 18161 263.5 MB 75.4 MB Rack: /rails_apps/my_app/current Is that typical...

Can't rake db:migrate due to sqlite3_busy timeout

I'm running RVM with ruby 1.9.2 and rails 3.0.0rc and when I run rake db:migrate I get Expected argument 0 of type sqlite3 *, but got SWIG::TYPE_p_sqlite3 #<SWIG::TYPE_p_sqlite3:0x00000... in SWIG method 'sqlite3_busy_timeout' Has anyone run into this? And more importantly, has anyone fixed it and how? ...

How do I make get attr_accessor_with_default work with a collection?

I want to give one of my models an attribute accessor that defaults to an array of eight zeros. This is the first syntax I tried: attr_accessor_with_default:weekly_magnitude_list, [0,0,0,0,0,0,0,0] The above didn't do what I expected because all instances of the model end up sharing the same Array object. The blog (http://barelyenough...

What are the benefits and the commands to use the new Bundler?

I have been using Rails for a couple years now and took a break away for a few months and just found myself back on a Rails application. The only problem is I don't know how to use bundler. I've been doing research and I find the command bundle install but what others are there and does this actually install the gems locally or just ...

Ideal Rails Server

What is the ideal rails server? Lets assume its on a VPS, such as Linode. Lets assume that any of the sites won't become the next twitter, but they should scale well. It must also support multiple sites and all sites are rails 3. And the database must be on the same server (for now). Should it use apache or nginx? Ruby Enterprise Editi...

Cucumber can't find routes? This is potentially a big newb question.

Rails3 app with Rspec2 and Cucumber Cucumber Given /^that a user is logged in$/ do current_user = User.first render new_user_post_path(current_user) end Routes.rb map.resources :users do |users| users.resources :posts, :collection => {:view => :get} end posts_controller_spec describe PostsController do describe "#new" do ...