ruby-on-rails

Accessing two sides of a user-user relationship in rails

Basically, I have a users model in my rails app, and a fanship model, to facilitate the ability for users to become 'fans' of each other. In my user model, I have: has_many :fanships has_many :fanofs, :through => :fanships In my fanship model, I have: belongs_to :user belongs_to :fanof, :class_name => "User", :foreign_key => "fanof_...

Switching from PHP to Ruby - is it the answer to performance?

Hi everyone, I get more often the answer, when asking performance related stuff regarding PHP applications, that PHP really isn't the language for high-performance applications, and that a compiled language really is the way to go. The only thing holding me back to PHP is that it's what I have learned to work with for some while now an...

Unit Testing a rails 2.3.5 plugin

I'm writing a new plugin for a rails 2.3.5 app. I've included an app directory (which makes it an engine) so i can easily load some extra routes. Not sure if that affects anything. Anyway, in the test directory i have two files: test_helper.rb and my_plugin_test.rb These files were generated automatically using script/generate plugin...

How to make parameters optional when using Rails named routes?

I have a named route: map.find '/find/:category/:state/:search_term/:permalink', :search_term=>nil, :controller=>'find', :action=>'show_match' and the following URL matches it & works OK: http://localhost:3000/find/cars/ca/TestSeachTerm/bumpedupphoto-test but if I take out the 2nd last parameter i.e. "TestSearchTerm", then the rout...

Agile web development with rails

Hi.. This code is from the agile web development with rails book.. I don't understand this part of the code... User is a model which has name,hashed_password,salt as its fields. But in the code they are mentioning about password and password confirmation, while there are no such fields in the model. Model has only hashed_password. I am s...

Creating a Calendar/Planner Application - Ruby on Rails...

I am considering developing an application using Ruby on Rails that is a planner of sorts. I would like to give a user the ability to see a list of days, click a particular day, and then add things like: Meals, Expenses, Events, Todos, and Exercises. Really I am doing this for me and my growing family. I am curious with how best to imp...

Ruby On Rails Routes

I can't figure out how to get the following routes. Here's an extract from my routes.rb file: map.resources :treatments map.root :controller => "home" map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' map.connect ':action', :controller => 'home' # replaces the need to manually map pure action...

How can I get model names from inside my app?

I have a bunch of models in a sub-directory that inherit from a model in the models root directory. I want to be able to set a class variable in another model that lists each inherited model class. i.e @@groups = sub_models.map do { |model| model.class.to_s } Not sure how to get at this info though... ...

Ruby on rails list to columns

How to create ruby on rails list(index page) like this: 1 | 2 | 3 4 | 5 | 6 7 | 8 | 9 10| 11| and so on. ...

How to create read-only virtual attributes in Ruby models

I would like to create a virtual attribute that will always be included when you do model_instance.inspect. I understand that attr_reader will give me the same thing as just defining an instance method, but I would like this attribute to be part of the object's "make up" How can I accomplish this? Thanks! UPDATE Here is what is not ...

How do I debug random Timeout::Error: execution expired

We are using Rails 2.3.5 and have been experiencing seemingly random Timeout::Error: execution expired errors. The errors reported by Hoptoad are not consistently in any particular controller and show up everywhere from user sessions to account settings to some of our core functionality controllers. The vast majority of requests do not...

Rails - how to serialize a tree not in a form

I started with the standard scriptaculous drag and drop tree, and that all works fine. Then started implementing this: http://www.artweb-design.de/2008/5/30/scriptaculous-sortabletree which gives a good drag and drop tree Where I am stuck is how to get serialize the tree (unordered list)? It's not in a form, and I can't find a way to s...

Is there a definitive solution for auto_complete in Rails?

I'm using DHH's auto_complete plugin, but am in the process of updating my dependencies on plugins to gems where feasible. Is there a newer, gemified version of this library, or has another solution emerged as the de facto standard? ...

Rails - Paperclip, getting width and height of image in model

Trying to get the width and height of the uploaded image while still in the model on the initial save. Any way to do this? Here's the snippet of code I've been testing with from my model. Of course it fails on "instance.photo_width". has_attached_file :photo, :styles => { :original => "634x...

Rails Tagging using Acts_As_Taggable_On: Finding All Tags in a Context

In a blog system I'm working on, I want to use tags as a mechanism for deciding where a particular post shows up. I'm using acts_as_taggable_on to set up two contexts, the normal :tags context and then the :audience context. I'm using an account model to tag the post model like so: account.tag(post, :with => "cat1, cat2", :on => :au...

ruby on rails: How do I access variable data in a url parameter passed to a model?

I have a variable called "account_type" passed from a rails form and need to access the value in the corresponding model. I can check if :account_type exists as a symbol, but where does the stored data come into play? Is there something I need to do in the controller? This code gives an undefined method 'account_type' error. validates...

cant use Activerecord find method with associations.

here are my models: #game class Game < ActiveRecord::Base #relationships with the teams for a given game belongs_to :team_1,:class_name=>"Team",:foreign_key=>"team_1_id" belongs_to :team_2,:class_name=>"Team",:foreign_key=>"team_2_id" def self.find_games(name) items = Game.find(:all,:include=>[:team_1,:team_2] , :conditions ...

rails conditional find based on datetime with timezone

I have a rails (2.3.4) application and want to send users a daily update via mail. To make things more comfortable, users can choose the time when they want their daily mail. My question: how should I store and more importantly lookup this time so as users' time zone, in particular daylight savings are respected? Currently, we save a 'p...

Using named_scope in to_json / as_json serialization

example: Person has_many Comments. Comments has named_scope :approved. And I need to serialize Person with all approved comments to JSON. So it should look like this: person.to_json(:include => :comments) but how can I add there that named scope? To serialize just that approved ones? ...

Order awesome nested set array for combo box lookup

I'm using Awesome Nested Sets and Formtastic within Rails and am having trouble listing the nester set records in a structured order within a lookup (combo) box. I'd list to show the lookup box like so: -Parent1 --P1Child1 --P1Child2 -Parent2 --P2Child1 --P2Child2 --P2Child3 etc... Origionally the lookup box was displaying the resul...