ruby-on-rails

Writing a simple conditional statement in IRB

I am looking up all Organizations with the url "http://", and updating their attributes to "". My attempt: Organization(:all).select { |o| o.url = "http://" ? o.update_attribute("url","")} Which returns a compile error: SyntaxError: compile error (irb):2: syntax error, unexpected '}' from (irb):2 Any ideas? ...

Mysterious Redirect in Rails

HI all, I have a problem with getting an unexpected 302 redirect in my rails app where after calling a controller method which has an associated view (the controller has no redirects or renders), in the development.log file we see a 302 redirect (not in the routes file) and we get redirected from the advanced_search method to the index ...

Running Anemone (or other web spider) Client Side

I am looking at building something around anemone but am wary that it will use a lot of my servers bandwidth. Am I right in guessing that anemone spiders from the server it lives on and not the client side that runs it? If that is true, is there a way I can get anemone (or any other ruby spider) to run client side? Thanks ...

Generating the input id with an ActiveRecord model

How do you generate an input's id attribute, given a model? For example, if I have a model of Person with a first_name attribute, the form helper prints out a textbox with this html: <input type="text" id="person_first_name" /> How can I generate that person_first_name from some other place in the code (like in a controller or some pl...

what does dash mean in ruby on rails html scriptlet ?

In the web I've seen examples both with <% if @showIt -%> some html content <% end -%> and without <% if @showIt %> some html content <% end %> dash. Both versions work very well. So, what difference does it make? Thanks! ...

rails ajaxful rating rating_averate doesn't update

I impleneted ajaxful rating on a Store model with 3 dimensions. I am caching rating average for each dimension as well as the overall average rating. The individual dimension rates are being saved and shown correctly and everything works fine except, the "rating_average" does not update (still at 0) even after multiple users have updated...

Failed to build gem native extension - extconf.rb not found

Hi, When trying to install 'bcrypt-ruby', :lib => 'bcrypt' and 'hpricot' I get this in both cases (Using Windows XP) C:/Ruby/bin/ruby.exe: No such file or directory -- extconf.rb (LoadError) I installed from here http://rubyinstaller.org/downloads/ Rb 1.8.6, including the devkit any hints?, thanks ...

Rails and Git workflow advice.

Hi Everyone, I need some advice with my desired setup with git and Rails. Basically for my first Rails application I used a base application template from GitHub, I then made a ton of changes and now have a full application which is fairly customised. I have now extracted all of the changes I made to the files within the base applica...

validate uniqueness amongst multiple subclasses with Single Table Inheritance

I have a Card model that has many CardSets and a CardSet model that has many Cards through a Membership model: class Card < ActiveRecord::Base has_many :memberships has_many :card_sets, :through => :memberships end class Membership < ActiveRecord::Base belongs_to :card belongs_to :card_set validates_uniqueness_of :card_id, :...

Searchlogic and :has_many, :through =>

I'm using Searchlogic to search on many fields in a database. One of those fields is a :has_may, :through => relationship, and I can't get it to work. Here are the relevant parts of the models: Source.rb: class Source < ActiveRecord::Base has_many :authorships has_many :authors, :through => :authorships end Authorship.rb: clas...

Is it possible to group validation?

I am using a lot of my own validation methods to compare the data from one association to the other. I've noticed that I'm constantly checking that my associations aren't nil before trying to call anything on them, but I am also validating their presence, and so I feel that my nil checks are redundant. Here's an example: class House <...

Basecamp API Rails

Hi Everyone, I was wondering if someone could do me massive favour.. I really don't understand how to make use of APIs - so I was wondering if, using Basecamp as an example, someone could talk me though the basics. So far I have an application with a dashboard controller/view, I have put basecamp.rb into my /lib directory, added the ...

Preparing for Rails deployment

Getting ready to deploy a rails project on Mac OS X Leopard Server (such that it matters). Got a few questions for someone with Rails experience: where should directory containing the project go? inside the website's root folder or out? who should "own" that directory? www? root? something/someone else? hope to continue serving static...

add_without_safety create new DB entry in controller

Im trying to get a controller to create a new account with the user id filled in, this doesn't work in my controller or in the console, why? Any suggestions on how to implement this would be much appreciated. class PaymentNotification < ActiveRecord::Base after_create :add_account_to_market private def add_account_to_market if s...

Why am I getting the error "undefined local variable or method `assigns'"?

I might be missing something basic here, but I'm stumped on this error: model code: class CachedStat < ActiveRecord::Base def self.create_stats_days_ago(days_ago, human_id) d = Date.today - days_ago.day @prs = PageRequest.find(:all, :conditions => [ "owner_type = 'Human' and owner_id = ? and created_at = ?", human_id, d] ) ...

Rails message: ActionView::MissingTemplate

I am getting an error that I cannot figure out: ActionView::MissingTemplate (Missing template cluster/delete_stuff.erb in view path app/views) <...snip trace...> Rendering rescues/layout (internal_server_error) I am "enhancing" others code and am following the convention they set up, where they have have code like: <%= render :partia...

Customizing Rails XML rendering to include extra properties

Let's say I have a model like this: create_table :ninjas do |t| t.string name end And the Ninja class with an extra property: class Ninja < ActiveRecord::Base def honorific "#{name}san" end end And in my controller I just want to render it to XML: def show render :xml => Ninja.find(params[:id]) end The honorific part...

Paperclip and Amazon S3 Issue

Hey everyone, I have a rails app running on Heroku. I am using paperclip for some simple image uploads for user avatars and some other things, I have S3 set as my backend and everything seems to be working fine except when trying to push to S3 I get the following error: The AWS Access Key Id you provided does not exist in our records...

Updating protected attributes using update_all in a migration

Since you cannot use the normal 'update' and 'update_attribute' methods from ActiveRecord to update a protected attribute, is the following the best way to update an attribute for a single user? User.update_all("admin = true","id = 1") I'm guessing this doesn't lie in the 'best practice' category, so I'm just curious if there is a m...

rails: "unknown action" message when action is clearly specified

hi, I had hard time to figure out why I've been getting "unknown action" error message when I was do some editing: Unknown action No action responded to 11. Actions: bin, create, destroy, edit, index, new, observe_new, show, tag, update, and vote you can see that Rails did mention each action in the above list - update. And in my f...