ruby-on-rails

What objects are passed into the view?

I'm guessing all objects that are local to the action are passed into the view? I never see sample code that actually specifies which objects are passed to the view! Is it good practice to create a 'model' object and then assign, as properties to the 'model' object, all objects you want to pass to the view? How can you explicitly pass...

Sortable plugin - doesn't work with related objects

Is installed this ruby on rails plugin for sortable paginated tables, but can't get it to work on related objects. git://github.com/kovacs/sortable.git http://javathehutt.blogspot.com/2009/06 … rails.html In the example given based on the User class, using the associated Role class, there is a :table_heading of ['Role', 'role'], a :sort...

Bunder.require does not work for ActiveRecord in my gem

I just created a new gem (using bundler) and want to add Active Record support. So I added s.add_dependency "activerecord", "~> 3.0" to my gemspec. Then I use Bundler.setup and Bundler.require and thought that I have access to Active Record now, but I haven't. I have to explicitly use require "active_record". Any idea why Bunder.require ...

How to run a rake task right after rspec initializes the database

I have a Rails 2.2 app that I'm supporting and one thing that needs to be done before the app start is a small rake task to initialize and make sure the database is properly set. How can I get this task run right after rspec initializes the database. I run rspec using the rails spec command. ...

Correct Rails 3 replacement for ENV["RAILS_ENV"] ||= 'production' ?

We're doing an upgrade to Rails 3 (like half the world right now), and I've been diligently replacing usages of RAILS_ENV eg RAILS_ENV == 'wibble' # becomes Rails.env.wibble? But I'm not as certain of what to do with: ENV["RAILS_ENV"] ||= 'production' We've got it at the top of a whole bunch of rake tasks and daemons... and the id...

[rails 3] one-to-one mapping with a devise model.

Hello fellow developers, I am trying to model a one-to-one association with my devise model and for some reason, I cannot access the edit path for the dependent model. Here is what I mean: I have a CRUD controller for both a User and Credential model. User is a devise model. class Credential < ActiveRecord::Base belongs_to :user end...

Rails 3 -NoMethodError (undefined method `original_filename

Hello! I'm using Rails 3, Uploadify, to send images to S3. Right now all the images being upload have the MIME: application/octet-stream I'd like to fix that but I'm getting the following error: NoMethodError (undefined method `original_filename' for #<ActiveSupport::HashWithIndifferentAccess:0x107c81998>): app/models/photo.rb:29:in...

Doing an action in Rails without changing site

Good day... Still a beginner question. I mostly asking to save myself hours of trial and error... I had those already and there was no result. What I wanna do... I have a controller that has an action, of course. I want to send this action two IDs, it should make some database entry of those. No problem, the action works well. But I d...

How do I get Heroku to work on Ubuntu 10.10 (using VirtualBox on Windows machine)?

I'm a newbie following the RailsTutorial.org program and have installed/setup rvm, ruby 1.9.2,rails, curl, git and created my first app and pushed it to github (so the SSH key is fine). The next step is deploying to Heroku, which is killing me: gem install Heroku works fine but I get this error after "heroku keys:add" or "heroku crea...

What's the Rails Way to get the Model Class from the Controller?

I can do this in the controller to get the model class: self.class.name.gsub("Controller", "").singularize.constantize But is there a built in method for this in the controller? Something like self.model_class? Thanks! ...

Removing duplicate db migrations from git repository

I'm trying to deploy a rails app to Heroku and I'm running into some basic git problems. I'm new to this all -- rails, git, heroku -- so I'm afraid I'm getting lost on what's probably a fairly basic concept. I've pushed the app to Heroku, but when I'm migrating the db ($ heroku rake db:migrate), I keep getting the following error: rake...

How do I model these relationships?

I have a contact model, this includes name, address, phone number, etc. I have a user model which should have_one contact. I have a Customer model which has_many contacts. I have a Producer model which has many contacts. A contact can be only a user, a user and a customer, a user and a producer, or any combination of these three. I a...

Must I always use a form in a tabular interface in Rails?

I have a list of users that have requested access to my application. They appear in a table inside a view: <table> <thead> <th>Company</th> <th>First Name</th> <th>Last Name</th> <th>Email</th> <th>Role</th> <th>Action</th> </thead> <% for ar in @brand.access_requests %> ...

Setting up a feed with Rails

Hi, I have a country model and a places model - a country has_many places, and a place belongs_to a country. A place model also has_many posts (which belong_to a place). I would like to aggregate all the posts from places that belong to a certain country into a feed - rather like a friend activity feed on a social networking site. I'm h...

Effective usage of :finder_sql in has_many associations in Rails

In ActiveRecord models you can specify custom SQL-request for has_many associations. For example, class User < AciveRecord::Base has_many :events, :finder_sql => 'SELECT something complex' end While user.events returns what I need, the number of records returned can be huge, so I need to have a way to pass parameters for LIMIT. Is t...

Rails & RMagick

I've been doing some cool stuff with rmagick on my rails app. I tried starting up my project with 'rails server' and I got this error. I believe I have imagemagick and rmagick installed so I don't know why I see this error. /Users/devinross14/.gem/ruby/1.8/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require': no ...

Is it possible to run a find_by_sql query in Rails / ActiveRecord without loading all results into memory?

I'm building a Rails plugin that extracts a lot of data from Rails apps. It builds queries dynamically that span multiple tables, and there will be a lot of results returned. Here's an example of one of the queries built for pulling purchase data out of a Spree (Rails shopping cart): select orders.user_id as from_id, variants.product_id...

rails3: build child record

Hello, I have 3 models: user, wish_list and wishes: user has_one wish_list wish_list has_many wishes On my index page, I'm listing all the wishes of my current_user's wish_list in my controller's index method: @list = current_user.list @wish= @list.wishes.build in my index view, I want to put a form to add a new wish on top ...

Review system with login / signup required

I'm writing a review system for items in Ruby on Rails. I want the process to be as follow: users to start entering their review/ratings when they hit submit, if they're not logged in, users are redirected to the signup or login page, they create and account or signup they're redirected to the post where they wrote a review, and the ...

Rails3 not reloading code in lib while in development mode

THE SITUATION: I have code in lib/foo/bar.rb with a simple method defined as such: module Foo class Bar def test "FooBar" end end end In my helper, FooBarHelper, I have: require `lib/foo/bar` module FooBarHelper def test_foo_bar fb = Foo::Bar.new fb.test end end In my view, I call this helper method li...