ruby-on-rails

Rails generator m.directory returns can't convert nil into String

I have written this generator code but it returns 'can't convert nil into String' when I call m.directory inside the manifest. Anyone know what had happened? class AuthGenerator < Rails::Generator::NamedBase attr_reader :user_class_name def initialize(runtime_args, runtime_options={}) @user_class_name="User" @controller_clas...

How to begin with Ruby on Rails using Windows

I've tried downloading the Rails package and installing it on Windows, but have no idea to make it work. I have had some experience with this commbination: PHP 4.x + 5.x (Windows) LIGHTTPD (Windows) Connecting to a Firebird Database (Windows) Can anybody enlighten me? ...

defined? method in Ruby and Rails

I have a quite old templating system written on top of ERB. It relies on ERB templates stored in database. Those are read and rendered. When I want to pass data from one template to another I use the :locals parameter to Rails render method. For setting default variables of those variables in some templates I use the defined? method whic...

When should I be using "NOT NULL" in a MySQL table and are there any benefits?

I have the following rails migration: create_table :articles do |t| t.integer :user_id, :allow_null => false t.integer :genre_id, :allow_null => false t.string :url, :limit => 255, :allow_null => false t.string :title, :limit => 60, :allow_null => false t.text :summary, :limit => 350, :allow_null => false t.integer :votes_co...

How to use SQL_ASCII encoding in a rails application?

I have to connect to a legacy postgre database wich has ENCODING = 'SQL_ASCII';. How do I set this encoding in my rails app? ...

Why don't Searchgasm page links work?

I'm using the Searchgasm plugin for my searching and pagination. Everything seems to work great but the page links don't seem to work at all. Has anyone had this problem with Searchgasm before? Controller Code: class ArtistsController < ApplicationController # GET /artists # GET /artists.xml def index @search = Artist.new_s...

Send emails via gmail from different accounts

So I have action_mailer_optional_tls (http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls) and this in my enviroment.rb ActionMailer::Base.server_settings = { :tls => true, :address => "smtp.gmail.com", :port => "587", :domain => "www.somedomain.com", :authentication => :plain, :user_name => "someusername...

Rails meta plugin install script?

I wanna see if there is an approach to pack a few plugins together as a meta plugin that install everything together automatically, works like a project template. Why not a script? Because I want to put it in github so I don't have to worry about it when I am not with my own PC :) but of coz a script based solution is welcomed too. ...

How can I see the SQL ActiveRecord generates?

I'd like to check a few queries generated by ActiveRecord, but I don't need to actually run them. Is there a way to get at the query before it returns its result? ...

How can I add multiple should_receive expectations on an object using RSpec?

In my Rails controller, I'm creating multiple instances of the same model class. I want to add some RSpec expectations so I can test that it is creating the correct number with the correct parameters. So, here's what I have in my spec: Bandmate.should_receive(:create).with(:band_id => @band.id, :user_id => @user.id, :position_id => 1...

create object from xml string in ruby

I am trying to deserialize an object from xml in ruby. Something simple like u = User.new({:client_key => "Bar"}) v = User.new(u.to_xml) I get an error NoMethodError: undefined method `stringify_keys!' for #String:0x20fc7cc>. I'm not sure what I have to do in order to get the string from xml to an object. Update: @avdi gave me the...

Adding to multiple tables in rails

I'm sure this is a relatively simple question, and there must be a good sensible rails way of doing it, but I'm not sure what it is. Basically I'm adding books to a database, and I want to store the Author in a separate table. So I have a table called authors which is referenced by the table books. I want to create a rails form for add...

How do I retreive relevance value for ThinkingSphinx search results?

Is there any way to retrieve relevance values with results with the array returned by ThinkingSphinx? Percentages, points or whatever, just something I can work with? ...

Sharing code in respond_to blocks

I have the following before_filter: def find_current_membership respond_to do |wants| wants.html { @current_membership = @group.memberships.for(@current_user) } wants.rss {} wants.js { @current_membership = @group.memberships.for(@current_user) } end end I would like to share the code for the HTML and ...

text_field_with_auto_complete inside form_for

Simple question really - how do I use text_field_with_auto_complete inside a form_for block? I've tried doing f.text_field_with_auto_complete but that gives an error, and just using text_field_with_auto_complete by itself doesn't seem to do anything. Am I missing something here? ...

Can't Activate Rake (> 0.0.0) ??

Ok, this is very weird. I'm trying to do a database migration, and all of a sudden, I'm getting these errors: [C:\source\fe]: rake db:migrate --trace (in C:/source/fe) ** Invoke db:migrate (first_time) ** Invoke setup (first_time) ** Invoke gems:install (first_time) ** Invoke gems:set_gem_status (first_time) ** Execute gems:set_gem_sta...

Using jquery in Rails

I am planning to use jquery in Rails instead of prototype. I am not sure to use jRails or to use plain jquery and stay away from RJS. What do you think about this? EDIT: Two weeks later I found this http://www.loudthinking.com/posts/32-myth-3-rails-forces-you-to-use-prototype EDIT: This screencast is interesting too. ...

How do you generate rDoc for a particular plugin using rake

OK, I am trying to generate the rDoc for paperclip, but the rake task is choking on another plugin before it gets to it, so this is out of the question: rake doc:plugins I could go and fix up the broken plugin, but I'm busy and lazy, so I just want to generate the docs for paperclip. Is there any way of doing this? ...

How do I specify the "commentable_type" field with polymorphic associations?

I have two models, Article and Post that both inherit from a base model called ContentBase. You can leave comments on both Articles and Posts, so I am using a Polymorphic Association between Comments and Article or Post. However, since both Article and Post inherit from ContentBase, the commentable_type field ends up being "ContentBase...

Looking for suggestions for building a secure REST API within Ruby on Rails

I'm getting started on building a REST API for a project I'm working on, and it led me to do a little research as to the best way to build an API using RoR. I find out pretty quickly that by default, models are open to the world and can be called via URL by simply putting a ".xml" at the end of the URL and passing appropriate parameters....