ruby-on-rails

Writing proper validation errors ?

Update : Gutted entire question with more thorough description Ok same question with different names. In my model, I do validate the presence of. class QuickFact < ActiveRecord::Base belongs_to :organization validates_presence_of :quick_fact, :content But if either is blank, it errors out with : Missing template organizations/...

Rails 3 app server startup time is long

update: This started out as a question, but after working on this for a bit I think it might not be fixable. I figured I would post this in case anyone else is seeing the same thing and is wondering what is going on inside rails and bundler. Is anyone else seeing long load times in their Rails 3 apps? I placed timers in environment.rb...

cucumber problem when running with @javascript

When I run my feature file without javascript, it passes all tests in flying colors(okay, just one color, green) anyway, when I add @javascript to my last scenario, it suddenly fails the test. I tried tracing the problem by outputing it with puts: this is the culprit line: Then /^the "([^"]*)" option should be selected from the "([^"]*...

Rails 3 route name

Im using Cucumber + Capybara. This is how one of my step definitions looks like. When /^(?:|I )go to (.+)$/ do |page_name| visit path_to(page_name) end And here is my routing file: match "home" => "home#index" resources :searches root :to => 'firstpage#index' What is the name of a path? ...

Bi-directional polymorphic join model in Rails?

I'm working on a multi-site CMS that has a notion of cross-publication among sites. Several types of content (Articles, Events, Bios, etc) can be associated with many Sites and Sites can have many pieces of content. The many-to-many association between content pieces and sites must also support a couple common attributes for each conte...

Rails config.gem error on gem installed

I already have installed this gem: googlecharts.rubyforge.org, but I don't want to require it every time I need it on my actions, so I am trying to do it the Rails way: config.gem 'mattetti-googlecharts' Then I go and start my server and get this error: Missing these required gems: mattetti-googlecharts You're running: ...

How to load my rails console with spanish

I have set up a my application with spanish and english. On my console i am getting error messages in english if object is returning validation error. I want to set my rails console so i will get validation error message in spanish. ...

Devise ignoring custom strategy

This is just plain weird. I've got Rails 3 RC running with Devise installed. I've defined a custom strategy to try and use Kerberos for authentication. module Devise module Strategies class Kerb < Devise::Strategies::Base def valid? params[:username] || params[:password] end def authenticate! ...

How Can I Trigger a Scanner from a Browser?

I have Fujitsu fi-6130 TWAIN / ISIS scanners that I'd like to trigger from a button in a jQuery Rails web page. Not only would I like to have the page tell the scanner to "go", I'd also like to upload the resulting file via Paperclip once the (single) page is scanned - ideally without requiring the user to navigate a file explorer widge...

Helper for removing illegal characters?

I am using a user input string to create a url and I only want the url to contain lowercase letters and hyphens e.g. example.com/this-is-a-url In my model, I have added so far: def to_param name.downcase.gsub(" ", "-") end This makes it lowercase and hyphenated. How can I remove all illegal characters, such as '/"$£%& ...

A one-time generated CSV file in RoR

Is it possible to create a CSV file right out of the command line in IRB or elsewhere with a one-time use on it. Say, I just need a CSV file with all my user's first name on it. Can I create that without setting up any architecture? ...

Generate ruby classes from json document

Consuming a ruby json API, I want to save me some work and generate ruby objects off the bat. Any way to do this? so you could transform this: {"menu": { "id": "file", "value": "File", "popup": { "menuitem": [ {"value": "New", "onclick": "CreateNewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value...

How come this works and doesn't work in IRB?

I have Users . Users have_many :organizations If I do: User.find(:all).select {|u| u.organizations.first.name } it returns with: NoMethodError: You have a nil object when you didn't expect it! The error occurred while evaluating nil.name from (irb):33 from (irb):33:in `select' from (irb):33 Long story short: I am trying to find t...

Rails: How to use select in formtastic with activeRecord

I'm new to rails and I guess you can answer this question easily. What I got so far is = f.input :task, :as => :select, :collection => @tasks, :include_blank => true where the tasks collection is defined by Task.find(:all) within in the controller. This does in fact work, shows me a dropdown-list of all Tasks to select from and c...

How can I see on my iPhone the rails app is running on my mac via Passenger

Hi there, I'm developing a rails app, now I'm working on the CSS specifically for iPhone, on my mac. I've my app running via Passenger at http://whatever.local It'd be nice to access via iPhone to the same URL so I can test my CSS quickly. But how? Thank you, Leo ...

How to DRY up this conditional collection_select in form partial?

Hi all, I have a form partial that is being called in a content_for :sidebar. This collection_select should have "selected" set if the page calling the partial is a specific package page. Otherwise, it should have a "prompt" to select. How would I DRY this up? I tried an inline ternary on a single collection_select to no avail. <%- if ...

usecase diagrams in rails

Hi, Is there any way or plugin/gem for generating usecase diagrams from a given set of data(like actors, actions etc) in rails? I noticed a usecase generator plugin on netbeans portal but I did not find any documentation for it. Has anyone used this plugin or knows how to use it? ...

gettext problem with validation message.

I have a validation message self.errors.add_to_base(_("country cannot be deleted #{self.country_name}")) this is not working. But simple messages like self.errors.add_to_base(_("country cannot be deleted")) working fine. I am converting this messages to spanish. Any idea or solution? ...

respond_to json gives error: no route matches "/schedules/list.json" with {:method=>:get}

Hi I am a newbie trying to make a webservice that talks JSON. I have this in my controller: class SchedulesController < ApplicationController   def list     @schedules = Schedules.all     respond_to do |format|       format.html # list.html.erb       format.json { render :json => @schedules.to_json }     end   end end I have nothing...

Rails tries to execute Update action instead of the one I want

I want to develop an ajax functionality for commenting posts in my website. I've done this before, but I don't know why I'm having problems this time. Rails executes Update action from posts_controller, instead of the action called "save_comment". This is the relevant line of my routes file: map.connect "/posts/save_comment", :control...