ruby-on-rails

Using rails gem geokit sort by distance and pagination?

I come across a small issue in my app. I'm currently using geokit to find objects near a given location, and I use the sort_by_distance_from on the found set. See below: @find = Item.find(:all, :origin =>[self.geocode.lat.to_f,self.geocode.lng.to_f], :within=>50, :include=>[:programs], :conditions=>["programs.name = ?", self.name]) ...

Passing parameter from view in a link to specify my index in Rails

What I do and it's working : *in skills_Controller.erb* : def index @skills = Skill.all end def fetch_skills(conditions) @skills = Skill.find :all, :order => 'id DESC', :conditions => conditions end def skilloffer fetch_skills ["community_id = ? AND request = ?", @current_user.community_id, f...

Are there 3 forms to invoke production, staging, etc in Ruby on Rails for rails server, rails console, and rake?

The forms I know of are: For Rails 3.0: for rails server: rails server -e production for rails console rails console production for rake rake db:migrate RAILS_ENV=production Is that it? I know for rails runner and rails dbconsole, it is -e production as well. Are there more forms and what are other ones that use -e vs just ...

Display local time in view

In config/application.rb I have "config.time_zone = 'UTC'" (without quotes) in the file. I am assuming this is to make the conversion from the user's time, which is entered into the view, to UTC, which is stored in the database. My question is, how do I convert the UTC value from the database to the user's local time to display in the ...

How to delete an object of a has_many where the parent object is not yet saved

I have an @activity that has_many :clientships When creating a new object I assign several Clientship objects but before saving, the user wants to pick out a few to delete. How would I delete one of the following Clientship objects based on a user-defined client_id? The collection looks like this: @activity.clientships [ #<Clientsh...

How do you change Rails version on a mac?

I've got Snow Leopard with Rails 2.3.5 installed along with other versions (2.2.2 and 1.2.6). I'd like to use 2.2.2 as the webserver I want to deploy to uses a 2.2.x version of Rails. I've tried to uninstall Rails 2.3.5 but get this error: ERROR: While executing gem ... (Gem::InstallError) cannot uninstall, check `gem list -d rai...

Haml add class dynamically to an element

Hi, I've an element TR in my view, I want to add classes dynamically on this element depending on an association between 2 models (many to many between company and packaging). The result should looks like <tr class="pck1 pck3 pck5"> where pck1, pck3 and pck5 are packaging associated with a company Thanks for your insights ...

Rails 3 using fields_for in view doesn't work

Hello. I'm trying to implement master detail in a rails form with fields_for. I have one model called Recipe: class Recipe < ActiveRecord::Base validates :name, :presence => true validates :directions, :presence => true has_many :recipe_ingredients end and one model called RecipeIngredient: class RecipeIngredient < Activ...

Cannot use sqlite3 with ruby 1.9.2 and rails 3.0.0 on windows

I have first to explain a little bit my context, then the question: I have used Ruby on Rails now for 3 years with different applications, and upgraded from 1.2 up to 2.3.9. I want to upgrade to 3.0.0 as fast as possible. All I have read about it told to use the current version 1.9.2 of Ruby to work with Rails 3.0.0, so I installed the...

Rails 3 or 2.3.x?

Am afraid this is not exactly a programming question. I'm beginning to learn Rails. Should I start with rails 3 or learn rails 2.3.x first and then come to 3? Any help would be appreciated. Thanks. ...

In a Rails log file, what does "Processing by ProductsController#index as */*" mean?

In my Rails log file, I see lots of Started GET "/" for 63.148.78.244 at Fri Sep 24 19:03:39 +0000 2010 Processing by ProductsController#index as HTML I understand this means Rails is serving up an HTML page. However, what does this mean? Started GET "/" for 63.148.78.244 at Fri Sep 24 18:05:51 +0000 2010 Processing by Products...

How to find a hash key containing a matching value

Given I have the below clients hash, is there a quick ruby way (without having to write a multi-line script) to obtain the key given I want to match the client_id? E.g. How to get the key for client_id == 2180? clients = { "yellow"=>{"client_id"=>"2178"}, "orange"=>{"client_id"=>"2180"}, "red"=>{"client_id"=>"2179"}, "blue"=>...

is ruby on rails (or at least the community) dying?

This is an honest question and I am not trolling. As a newbie to rails I've been search for good rails resources. But I've been noticing many sites that apparently were once popular now being completely abandoned. Some examples: http://www.softiesonrails.com/ - last updated Feb 2010 http://www.therailsway.com/ - last updated Aug 2009...

named routes with devise in Rails 3 haml view

from rake routes I get this in my application new_admin_session GET /admins/sign_in(.:format) {:controller=>"devise/sessions", :action=>"new"} admin_session POST /admins/sign_in(.:format) {:controller=>"devise/sessions", :action=>"create"} de...

cache_money for Rails 3

I've used various forks (mostly the ngmoco fork) of Nick Kallen's excellent cache_money for several Rails 2.3 based project, but we're now making the leap to Rails 3 which, thanks to the introduction of ActiveRelation, does not work with the popular forks of cache_money. Is there a fork of cache_money, or an equivalent write-through ca...

Upgrade to Rails3 from Rails3.rc2, and forms are blank

Why does the following code work in Rails 3 rc2 but not in Rails 3? <%= form_for :product, Product.new, :url => products_path() do |f| %> <%= f.text_field :name %> <% end %> I have formtastic installed but when I took it out I get the same result. I started this project before Rails3beta 1. Should I have...

Rail3 - Browser is asking for a username & password when not signed in

Hello, recently my Rails 3 app started asking for a username and password via a browser prompt when loading the home page and not signed in... <%= javascript_include_tag :all, :cache => true %> I was able to determine that it's the line above causing the issue. If I remove that it doesn't happen. Ideas? Have you seen this before ? T...

Rails 3 - including JavaScript on a View?

Hello, here's what I'm trying to do right.... When a user signs in and is redirect to the landing page, I want to run a bit of jquery ajax to grab and inject some content. I originally had it in my application.js file but the problem with that is that the code is there for user's that aren't logged in, which means I have to add logic to...

Mongoid named scope comparing two time fields in the same document

I need to create a named scope in Mongoid that compares two Time fields within the same document. Such as scope :foo, :where => {:updated_at.gt => :checked_at} This obviously won't work as it treats :checked_at as a symbol, not the actual field. Any suggestions on how this can be done? Update 1 Here is my model where I have this scop...

Rails 3 LIKE query raises exception when using a double colon and a dot

Hi, In rails 3.0.0, the following query works fine: Author.where("name LIKE :input",{:input => "#{params[:q]}%"}).includes(:books).order('created_at') However, when I input as search string (so containing a double colon followed by a dot): aa:.bb I get the following exception: ActiveRecord::StatementInvalid: SQLite3::SQLExc...