ruby-on-rails

Rails - Why would I get the following output?

In running through the basic rails tutorial section about outputting comments, I get the following displayed: Comments Commenter: Me Comment: Hi #<Comment:0x1052af610> In the view I have: <h2>Comments</h2> <%= @post.comments.each do |comment| %> <p> <b>Commenter:</b> <%= comment.commenter %> </p> <p> <b>Comment:</b> <%= c...

rspec user story feature vs cucumber

Just to be up front, although the title appears to be similar to the thread http://stackoverflow.com/questions/393622/rspec-vs-cucumber-rspec-stories, however my question is fundamentally different. I understand the difference between testing user stories and testing behavior of objects individually. My question is, why is Cucumber usua...

ImageMagick / RMagick - Can't install RMagick 2.13.1. Can't find Magick-config

I used a script to install ImageMagick http://github.com/masterkain/ImageMagick-sl After a while, I got ImageMagick installed. Then I ran sudo gem install rmagick and got Building native extensions. This could take a while... ERROR: Error installing rmagick: ERROR: Failed to build gem native extension. .rvm/rubies/ruby-1.9.2-p0/bin...

Rspec, shoulda and spork does not work together

Hi all, when I run rspec spec/models result is OK. But when I use spork, every test where shoulda macros (like it { should validate_presence_of(:title) } is used FAILS with error like: undefined method 'validate_presence_of' for ... I use: rails (3.0.0) shoulda (2.11.3) spork (0.8.4) rspec-rails (>= 2.0.0.beta.22) spec/spec_helper....

Rails Join Table Problem

I am working on a rails project and am having some issues with the following join: @page = Page.find(params[:id], :joins => "LEFT JOIN page_translations ON page_translations.page_id = pages.id") For some reason its only pulling back everything from the Pages table. Here is my model for Page class Page < ActiveRecord::Base has_many...

i18n missing interpolation argument

Hi, i've developed a small website in rails 2.3.5 but when i wanted to deploy it on a server i started to get some issues. One of those issues is an interpolation problem. Whenever i want to format a date using i18n i'm getting this exception: ActionView::TemplateError (missing interpolation argument in "%{count} %B %Y, %H:%M" ({:object=...

Associating users with nested models in rails

I just added users to my app using Authlogic and CanCan. I just have a quick question about best practices for associating users to my other models. I have 3 models that are nested within each other with one-to-many associations like this: SENTENCE > WORD > LETTER So a sentence has many words, and a word has many letters. I am just ...

How do I stop Rails from misidentifying this class in a polymorphic :belongs_to?

I'm moving some code from being pulled in via SVN's externals function to be part of the code base proper. It's all Rails plugins and doing this seems to have broken part of my code. It seems like Rails is misinterpreting a :belongs_to statement. I have belongs_to :target :polymorphic => true in one of my classes and previously that has...

Is there a more efficient way to update the order of a collection of objects in Rails 3?

Suppose I have a collection of Pages that are ordered by a column called :sibling_order. Is there a more efficient way to update the ordering of the collection than what I'm doing below: class Page < ActiveRecord::Base ... def update_order(order) if (order < self.sibling_order) siblings = Page.where("parent_id = ? AND sibling_or...

What is the best way to ban/block users with Devise for Rails?

I'm using Devise for authentication in my rails app and I'd like to be able to block certain accounts and prevent users from reregistering with a blocked email. I'm just not sure what the best way is to go about it. My first thought was to override the sessions and registrations controllers to check the model for a user with a blocked ...

Rails 3 - Building a Table, Want to Alternate colors every row

Desired Output: <ul> <li class="odd">stuff</li> <li class="even">stuff</li> <li class="odd">stuff</li> <li class="even">stuff</li> <li class="odd">stuff</li> <li class="even">stuff</li> <li class="odd">stuff</li> <li class="even">stuff</li> </ul> CSS: .odd {color:blue} .even{color:red;} In rails 3 is there a clean way to do...

Rails 3, HowTo - Pass a Setting to the Application.html.erb

Most of my views will required a wrapper of padding 10px,,, but a few will not... I was thinking of doing something like this in the view controller: respond_to do |format| format.html { render :layout => true, :padding => 'false' } And then in the application.html.erb have an IF to not add a padding class if :padding is false......

Rails - Saving Nested Arrays

I was able to create nested arrays in my view to post to my 'create' action. But I'm not sure how to save the nested array. Here's the basic create action where it gets all individual params bunched in mass-assigned params: def create @post = Post.new(params[:mass_assigned]) respond_to do |format| if @post.save format.htm...

How to show an auto-incremental ID on a "create new record" form with Rails

I'm trying to create a form that will show the id that the record is going to have, prior to hitting submit on the form. For example, if I have a form to create a new project, and the previous project was id 3, I want the new project form to autopopulate with 4, so that I know that it's going to be 4 before I submit the form. Thanks for...

Tricky ActiveRecord + SQL Query (Refactor)

Here's my current named_scope. It returns an aggregate result from a number of rows. Sample result from 300 rows: Total Points: 3000 Wins: 31 Losses: 11 Here is the code: named_scope :open_for, lambda { |sportable_id, sportable_type, days_ago| { :conditions => ['sportable_id = ? and sportable_type = ? and game_time > ? ', sport...

How can I run a migration on my production database but not my development database?

I have a development database on my computer and a production database on Heroku. I need to run a migration on the production database, to clear certain data, that I don't want to run on the development one. So far I've only been doing migrations that I've wanted to run on both, so I just create it on my computer, run it, then when I upl...

Rails 3- Handling a conditional Create in a Controller

Hello, I have the following in my def create controller: @photo = current_user.photos.create(params[:photo].merge(:project_id => params[:project_id]) In my app photo records are valid if they have a project_id or not.... But I need my create statement not to error and work for both cases. A. If there is a param project_id, insertit...

There has got to be a cleaner way to do this...

I have this code here and it works but there has to be a better way.....i need two arrays that look like this [ { "Vector Arena - Auckland Central, New Zealand" => { "2010-10-10" => [ "Enter Sandman", "Unforgiven", "And justice for all" ] } }, { "Brisbane Entertainment Centre - Brisbane Qld, Aus...

Rails ActiveRecord association "one or the other"

I was wondering, how an association like the following might be done in Rails: class Car < ActiveRecord::Base belongs_to :person end class Truck < ActiveRecord::Base belongs_to :person end class Person < ActiveRecord::Base #How to do the association as below? has_one :car or :truck end Essentially, I am trying to enf...

Rails - refresh/render question after select box onchange event

Hi there, I have a paginated list, and a select box of numbers showing how many pages to display. When the user picks a value I want the screen to refresh with the resized list. View: <%= select_tag :paginate_size, options_for_select([['Display: 5', 5],['Display: 10',10],['Display: 20', 20],['Display: 30', 30],['Display: 50', 50],['...