ruby-on-rails

Rails ActiveRecord updating fields

My Example: class Category < ActiveRecord::Base has_many :tags, :as => :tagable, :dependent => :destroy def tag_string str = '' tags.each_with_index do |t, i| str+= i > 0 ? ', ' : '' str+= t.tag end str end def tag_string=(str) tags.delete_all Tag.parse_string(str).each { |t| tags.build(:tag...

Rails 3 can not find sqlite3-ruby

I am trying to learn rails3. I tried folowing the installation guide from guides.rails.info, I installed sudo gem install rake rack-test rack-mount erubis mail sudo gem install tzinfo builder i18n memcache-client sudo gem install text-format thor And rails 3 via sudo gem install rails --pre Now I create a new app rails abc And...

OpenURI::HTTPError: 403 Forbidden

Hi, i'm using wikipedia-api plugin for get content's pages from wikipedia. From some days i receive this error when i try to get the contents: page = Wikipedia.find_by_titles('Foo') OpenURI::HTTPError: 403 Forbidden from /usr/lib/ruby/1.8/open-uri.rb:277:in `open_http' from /usr/lib/ruby/1.8/open-uri.rb:616:in `buffer_open' ...

Ruby on Rails: How would I add a link from a custom plugin to my app's navigation?

I'm trying to add a navigation link from a plugin that I made without altering the main app files. For example, say that I have this: app/views/shared/_navigation.html.erb <ul id="navigation"> <li><a href="#">Nav link A</a></li> <li><a href="#">Nav link B</a></li> <li><a href="#">Nav link C</a></li> </ul> If I have a custom plugin...

Why would I ever want to revert a migration?

In Rails, migrations have a down method by default for reverting a migration. In what scenario would I ever want to revert a migration, though? Some thoughts: Whether in development or production, I always have a snapshot of my database to go back to, before I even run the migrations. Especially for migrations which perform data conver...

Paperclip and xhr.sendAsBinary

Hi, I use paperclip to add a file to my model. I want to use the new feature of firefox 3.6, xhr.sendAsBinary, to send a file with an ajax request. Here is how I build my request : var xhr = new XMLHttpRequest(); xhr.open("POST", "/photos?authenticity_token=" + token + "&photo[name]=" + img.name ...

How can i conditionally style a <li> in rails?

I have a rails app using a ul as a toolbar. I want to have a style (selected) to apply to the page the user is on. How can I do that? This is what I have so far, but the selected style is hard coded and I'm also not sure how to know what page is selected. <ul> <li class="firstItem"><%= link_to "About", '/about' %></...

$" surviving between calls

I have an odd situation where $" seems to be surviving between calls, but nothing else does. It's returning properly the first call, and fail each additional request. This should be global information, so It won't work just to put it in a session. The comments show what logging returns, but my experience with "FileImport.installed_for...

ROR very slow in development while production works fine

I have one rubyonrails app that turned really slow in development mode. Everything is fine in production, but even a simple "hello world" takes seconds in dev. I checked the session store and every possible reason i found on the net, but I didn't find the problem. Am I missing something that is common knowledge? "Completed in 1657ms (Vie...

How to avoid nginx "upstream sent too big header" errors?

I'm running nginx, Phusion Passenger and Rails. I am running up against the following error: upstream sent too big header while reading response header from upstream, client: 87.194.2.18, server: xyz.com, request: "POST /user_session HTTP/1.1", upstream: "passenger://unix:/tmp/passenger.3322/master/helper_server.sock It is occuring o...

rake db:migrate throws undefined method 'symbolize_keys' for nil:NilClass

Working with rails for the first time and I getting a rake error when I try: rake db:migrate RAILS_ENV=staging The Error: (in [my current directory]) rake aborted! undefined method `symbolize_keys' for nil:NilClass Has anyone seen this? ...

Is there a Rails or JQuery date picker that includes a predefined set of named ranges?

Before I roll my own (again, I already did this once in Java), is there a date picker that allows predefined named ranges in addition to the standard user-chosen dates. For example, I want the user to be able to choose 'Today' or 'This Week' or 'Last Month' and store it in such a way that it's relative to the time I access it, not based ...

problem using accept_nested_attributes with polymorphic relations and inheritance

Having this mix of polymorphism and inhertiance, I encounter some weird behaviour: Migration class CreateCommons < ActiveRecord::Migration def self.up create_table :commons do |t| t.string :name t.string :configurable_type t.integer :configurable_id end create_table :specifics do |t| t.integer :nu...

Implementing vote_fu in rails app (or alternatives)

I've been attempting to implement a robust voting system in rails for some time but have been struggling. Initially I built my own voting system, but it was simplistic. In a nutshell it just incremented a votes_count column in the "Answer" model using the counter cache...this worked fine for me for a while until I discovered vote_fu......

ROR- Step by step multiple images using Paperclip.

I have used the "tutorial" on here but for some reason it didn't work. Can anyone give me a step-by-step guide for setting up a multiple image form (upload) with other form elements ... Also another tutorial (a good one) may be provided. I only want to use the paperclip plugin. @Gordon Isnor: I have uploaded my current (noob) project...

Splitting unicode (I think) using .split in ruby

Hi all- I am currently scraping an rss feed from last.fm and the title attribute looks like it has a unicode "-" that comes up as \u2013 on firebug. Here is the feed for those that are curious: http://ws.audioscrobbler.com/2.0/user/rj/recenttracks.rss When I write something like this feedentry.title.split('-') it won't find the un...

haml and no javascript? (rails: form_remote_tag and :with parameter)

i am trying to call a remote method to update page content via ajax/js. either i am too tired already or haml is not parsing the following code correctly to send the value of the query field via prototype. any ideas? - form_remote_tag(:url => {:controller => "search", :action => "line"},:with => "'query=' + $('query').value" ) do %inp...

put show action on a profile page

class ProfileController < ApplicationController def show username = params[:username] @user = User.find_by_username(username) if @user @title = "Profile for #{username}" user_id = @user.id @albums = Album.find(:all, :conditions => ["user_id = ?", user_id]) I have managed to display the index of albums for a give...

wrong number of arguments (1 for 0) has_many_association.rb:61

I am upgrading my app from Rails 2.2 to 2.3.5 and I am seeing the following error while using '<<' for saving a has_many relationship. Eg: Breaks test ev = UserEvent.new # model specific code here self.user_events << ev Eg: Works ev = UserEvent.new # model specific code here ev.user_id = self.id ev.save! This worked fine with Rail...

Rails migration error: undefined method `install_helpers' for ActionController::Routing::Routes:Class

Got a couple of Rails 2.3.5 projects that are giving me this error when I try to run a rake db:migrate. Wondering if someone else has seen it: undefined method `install_helpers' for ActionController::Routing::Routes:Class Migrations used to run fine. I've got a pretty tame routes.rb but a lot of gems and plugins, one of which may be th...