ruby-on-rails

Error when pushing to Heroku - ...appear in group - Ruby on Rails

I am trying to deploy my first rails app to Heroku and seem to be having a problem. After git push heroku master, and heroku rake db:migrate I get an error saying: SELECT posts.*, count(*) as vote_total FROM "posts" INNER JOIN "votes" ON votes.post_id = posts.id GROUP BY votes.post_id ORDER BY created_at DESC LIMIT 5 OFFSET 0): ...

How do I serve nested static content on Heroku?

I have a rails application with static content in the public directory (e.g. public/index.html) and additional static content in nested subdirectories (e.g. public/one/two/index.html). All the static content is served correctly if I run it locally via script/server but when I upload it to Heroku the top-level page loads correctly but t...

Dynamic fields with Thinking Sphinx

Hi! I'm building an application where I have products and categories. Category has_many properties and each property has a list of possible values. After a category is set to the product all properties show up in the form and the user can set that property to one of the properties possible values. My question is: Is it possible for Th...

Ruby on Rails has_one Model Not Supplying ID Column

I have a legacy rails (version 1.2.3) app which runs without issue on a number of servers (not to mention my local environment). Deployed to its newest server, though, and I now get ActiveRecord::StatementInvalid: Mysql::Error: #23000Column 'video_id' cannot be null errors. Below are the models/relationships, simplified: class Video < ...

catching timeout exceptions in rails seems to skip rescues and explode "all the way up"

I have a controller: class EventsController < ApplicationController def index begin SystemTimer.timeout_after(10, CustomTimeoutError) do sleep(11) end rescue CustomTimeoutError => e # swallow end end end For some reason the rescue statement is not catching the timeout but instead its bubblin...

unexpected kENSURE, expecting $end - Rails/Cucumber/Haml

Been having a problem with Rails/Cucumber/Haml. The below Haml file works perfectly in the development and live environments but fails in Cucumber with the following error: /app/views/competitions/show.haml:30: syntax error, unexpected kENSURE, expecting $end (ActionView::TemplateError) On line #30 of app/views/competitions/show.haml ...

invalid option: --autospec

/usr/local/bin/ruby -rrubygems -e "require 'redgreen'" /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec --autospec <files_here> -O spec/spec.opts invalid option: --autospec Test::Unit automatic runner. Usage: -e [options] [-- untouched arguments] which spec says "/usr/local/bin/spec" which autospec says "/usr/local/bin/autospec"...

Thin and Bundler on Windows Rails

Trying to get Thin working with Bundle on Windows, I know, major PITA but anyways, I'm new to Thin and Bundle gem, I'm on Ruby 1.8.6 and Rails 2.3.5 and trying to get someone else's app running on my laptop, the app uses Thin and Bundle gem to install gems required. I noticed that bundle created a .bundle folder under My Documents folder...

Validating and ActiveRecord model based on an associated Model's data?

Hi everyone. SCENARIO: Given that a model called Edition has its community feature enabled I want all Records under that Edition to validate for the community field When the community feature is disabled, the community field will NOT be validated Basically, I am trying to write a custom validation function at the ActiveRecord level...

Problem with url_for and named routes in ActionMailer View: "Need controller and action"

I'm attempting to provide a confirmation link in my user welcome email and I'm getting the following Rails error: Need controller and action! It makes a fuss about this line: <p>Please take a moment to activate your account by going to: <%= link_to confirm_user_url(:id => @user.confirmation_code) %>.</p> In my development.rb envir...

Rails functional testing without migrations

The name pretty much says it all. Does anyone know how to accomplish functional testing when you are not using migrations in Rails? I'd be open to any advice or third party libraries (if there are any). I thought of creating my own plugin to address this but it seems like a pretty big task and would rather not do this unless necessary. ...

Ruby: Dynamically calling available methods raising undefined method (metaprogramming)

I have an Activerecord object called Foo: Foo.attribute_names.each do |attribute| puts Foo.find(:all)[0].method(attribute.to_sym).call end Here I'm calling all attributes on this model (ie, querying for each column value). However, sometimes, I'll get an undefined method error. How can ActiveRecord::Base#attribute_names return an ...

Scope of Constants in Ruby Modules

I'm having a little problem with constant scope in mixin modules. Let's say I have something like this module Auth USER_KEY = "user" unless defined? USER_KEY def authorize user_id = session[USER_KEY] def end The USER_KEY constant should default to "user" unless it's already defined. Now I might mix this into a couple of p...

In Rails, is there a way to selectively load files in the view from application layout?

So in my Rails application, I'm trying to set up Javascript testing on certain views. Right now, I'm doing this by having a conditional in each view.. <% if AppConfig['js_testing'] %> <script> ... </script> <% end %> If I have it on each page, there's a lot of code duplication. Is there a way manage everything from the application la...

Complicted ActiveRecord Association. Going through a 4th table

I have kind of a complicated case and am wondering how this would work in rails: I want to categories the genres of some singers. Singers can belong to more than one genres, and users can assign tags to each genre For example: singers <-- singers_genres --> genres <-- genres_tags --> tags SQL would look something like: SELECT * FR...

Ruby on Rails: having two xmlbuilder templates per action , one for errors one for regular output

What's the best way to handle having two templates (or should it be one, DRY?) for xml builder templates? I'm building a web api with Rails and wanted to see an example of how to have a view that does regular output vs one that does error output. I've been using @obj.to_xml for a while, but my requirements have changed and require me bu...

Ruby on Rail using MYSQL database

Hey guys, New to rails, trying to figure out something simple. Seems as though I cannot migrate a very simple mysql database using "rake db:migrate" command. Here is the issue: I know rails defaults to sqllite right now, but I need to use mysql for a series of reasons. Use the following commands rails -d mysql MyMoviesSQL cd MyMovies...

Ruby on Rails bizarre behavior with ActiveRecord error handling

Can anyone explain why this happens? mybox:$ ruby script/console Loading development environment (Rails 2.3.5) >> foo = Foo.new => #<Foo id: nil, customer_id: nil, created_at: nil, updated_at: nil> >> bar = Bar.new => #<Bar id: nil, bundle_id: nil, alias: nil, real: nil, active: true, list_type: 0, body_record_active: false, created_at:...

Filtering records in controller

So in my model, there is a field user_id - which holds the ID of the user who created the record. To display the ID of the current user, I have @current_user.id My question is this, in the controller I want @posts to only have records created by @current_user.id how can I do this? ...

How to generate table of contents with prawn?

Is there an easy way to generate table of contents with links to corresponding pages? ...