ruby-on-rails

How to write SQL query as named_scope?

How can I translate the following SQL query into a named_scope? select users.*, sum(total_quantity * total_price) as points_spent from orders join users on users.id = orders.user_id where pay_type = 'points' group by user_id order by points_spent desc Thanks! ...

Adding a column to a model at runtime (without additional tables) in rails

I'm trying to give admins of my web application the ability to add some new fields to a model. The model is called Artwork and i would like to add, for instante, a test_column column at runtime. I'm just teting, so i added a simple link to do it, it will be of course parametric. I managed to do it through migrations: def test_migrati...

Rails tabs instead spaces

Is there any way to to setup Rails generating files with tabs instead spaces? Or maybe is there any way to auto replacing spaces to tabs in gedit? Cause I really prefered tabs and it's really take some time to replace spaces to tabs in new generated files by Rails. Thanks in advance! ...

Rails architecture questions

I'm building a Rails site that, among other things, allows users to build their own recipe repository. Recipes are entered either manually or via a link to another site (think epicurious, cooks.com, etc). I'm writing scripts that will scrape a recipe from these sites given a link from a user, and so far (legal issues notwithstanding) t...

Problem with writing a file to excel with spreadsheet

I am trying to write excel file by using ruby 1.9 spreadsheet version 0.6.4.1 on windows. Everything is going ok, until I get to the book.write statement when I write book.write "c:/spreadsheet/excel-file.xls I keep getting the following error No such file or directory - c:/spreadsheet/excel-file.xls when i am runing it from the ruby...

Authlogic admin subsite

Following this tutorial getting the following errors: NameError in Admin/dashboardsController#show uninitialized constant Admin::DashboardsController NameError in Admin sessionController#new uninitialized constant Admin::AdminHelper not sure how to correct this! ...

Should frontend and backend be handled by different controllers?

In my previous learning projects I always used a single controller, but now I wonder if that is good practice or even always possible. In all RESTful Rails tutorials the controllers have a show, an edit and an index view. If an authorized user is logged on, the edit view becomes available and the index view shows additional data manipul...

rails db migration, undefined method `to_sym', can't figure out syntax

the original migration looks like this: class CreateUsers true do |t| t.string :login, :limit => 40 t.string :name, :limit => 100, :default => '', :null => true t.string :email, :limit => 100 t.string :crypted_password, :limit => 40 t.string :salt, :limit => 40 t.string :remember_token...

Memcached and Rails Fragment Caching Issue

When I have 2 views that fragment cache the same query BUT display them differently, there is only one fragment and they both display it the same way. Is there any way around this? For example... #views/posts/list - cache(@posts) do - for p in @posts = p.title #views/posts/list_with_images - cache(@posts)...

How to remove trailing symbol for a constant in Rails initializer?

How does one remove trailing character correctly in the following sentence if it's in config/environment.rb file. KEY = ENV['KEY'].delete "\r" It produces the following error: undefined method `delete' for nil:NilClass (NoMethodError) It works well in IRB, but not in environment.rb Solved Aptana Studio 3 stopped to load .bashrc a...

Need to run Rails 2.2.2 but I have RubyGems 1.3.6 it wants 1.3.5

I have a Rails program that has 2.2.2 embedded. When I run it I get an error because RubyGems 1.3.6 is not compatible with Rails 2.2.2. I am running rvm and would like to set up an environment to run this program with ruby 1.8.7 and rubygems 1.3.5. Any help would be greatly appreciated. Barb ...

HTTP Push on Heroku

What would be the best approach to creating an application on Heroku that has the capability to push data to the client? I have looked at Juggernaut; however, it requires Flash and I am not sure about it actually running on Heroku. Any help would be appreciated. ...

Model self referential collections in Rails

I have written an application for an online clothing store in Rails 2.3.5. I want to show related Products when a customer views the Product Detail page. For example, if the customer views the detail page for a suit, I'd like to display the accessory products that match the dress such as a vest, shoes, and belt. I have named the relat...

How to set up RPX widget and facebook app to be able to authenticate with rpx_now?

Using the sample app for rpx_now gem ( http://github.com/grosser/rpx_now_example) on localhost:3000, I have successfully logged in via Google Accounts, myOpenID, Yahoo, but cannot make it via Facebook. In the RPX app/widget settings I have set my facebook-app key and secret. In my facebook app settings, the Connect URL is myappname.rpx...

How can I have a single helper work on different models passed to it?

I am probably going to need to refactor in two steps since I'm still developing the project and learning the use-cases as I go along since it is to scratch my own itch. I have three models: Letters, Calls, Emails. They have some similarilty, but I anticipate they also will have some different attributes as you can tell from their desc...

Gem installed and require but "Constant missing"

I have installed the gem 'simple_uuid' but nothing seems to be working. Using irb and running the following: require 'rubygems' require 'simple_uuid' is fine, both return true. But running the following: // Class added by simple_uuid UUID.new returns NameError: uninitialized constant UUID from (irb):3 from :0 I'm a rub...

I18n translation problem

I'm about to translate all time zones to Russian and I've done such things: model: # lib/i18n_time_zone.rb class I18nTimeZone < ActiveSupport::TimeZone def self.all super.map { |z| create(z.name, z.utc_offset) } end def to_s translated_name = I18n.t(name, :scope => :timezones, :default => name) "(GMT#{formatted_offse...

how can I have a teammate restart heroku server from his machine

I have a rails app up on heroku. Sometimes the server bombs out and I have to go to the console and execute heroku restart so that servers get restarted. This seems to fix the problem. However, I am not on my machine all the time. I would like to have a team member have this capability as well. For this to happen...what does he need...

Fragment caching

I would like to fragment cache part of a page. On the view I have <% cache("saved_area") do %> . <% end -%> In the controller: def index read_fragment("saved_area") end In config/production: config.cache_store = :file_store, File.join(RAILS_ROOT, 'tmp', 'cache') The file was created in the tmp/cache directory. ...

Validate HAML from ActiveRecord: scope/controller/helpers for link_to etc?

I like HAML. So much, in fact, that in my first Rails app, which is the usual blog/CMS thing, I want to render the body of my Page model using HAML (obviously I won't do the same for Comment!). So here is app/views/pages/_body.html.haml: .entry-content= Haml::Engine.new(body, :format => :html5).render(self) ...and it works (yay, recur...