ruby-on-rails

HABTM relationships and accepts_nested_attributes_for

I have a form that lets me create new blog posts and I'd like to be able to create new categories from the same form. I have a habtm relationship between posts and categories, which is why I'm having trouble with this. I have the following 2 models: class Post < ActiveRecord::Base has_and_belongs_to_many :categories attr_accessibl...

Passenger 2.2.5 - Apache turn off friendly Error Messages

I'm in production mode with Passenger 2.2.5 and Apache and would like to get rid of the friendly error messages. Preferably I would just like to see a 404 if anything goes wrong. I know Passenger 3.0 offers the PassengerFriendlyError off option, but afaik, 2.2.5 does not. ...

RSpec: Can I retain the new Rspec (2.0.x) with the old one (1.3.x) and still run autospec on 2.3.x Rails apps?

I gave Rails3 a try and to do so I installed the new gems, like RSpec2. When I went back to my old apps though, autospec stopped working for Rails 2.3.x apps: $ AUTOFEATURE=true autospec /usr/local/lib/site_ruby/1.8/rubygems.rb:335:in `bin_path': can't find executable autospec for rspec-2.0.1 (Gem::Exception) from /usr/bin/autospec...

How to make Cucumber step definitions load according to feature file being executed

Hi, I would like to modify cucumber so that when a given feature is being executed (say "login.feature") I want only login_steps.rb to be loaded for the web steps. Other step files should not be loaded. IMO this would be very useful to have the same steps but which differ in implementation work accordingly from the feature's name whic...

How to clear a session variable in rails (basically whats the best way)?

session[:message]=nil Is this is the best way to destroy a session variable. Note: *I dont want to clear all the session variables like reset_session do.* ...

RSpec sends emails (not storing in ActionMailer::Base.deliveries) - dont know why?

Hey, Im using rspec and when i run rake spec, the user mailer sends email through smtp and not stores the email in the ActionMailer::Base.deliveries-array (invoked by an user-observer)... Could you give me a hint why? # Rails version rails -v => Rails 3.0.1 # Ruby version with rvm (rvm version 1.0.16) ruby -v => ruby 1.9.2p7 (2010-09...

How to use psql triggers(procedure, function) in rails application?

I am trying to use psql triggers in my rails app. So i tried using this migration where execution of psql triggers are supposedly easly -- class AddTriggersToProducts < ActiveRecord::Migration def self.up table :products execute %q{ create trigger trig1 before insert on products for each row begin price...

[rails] Limit some url(i mean controller) to same local network user only

The system need to be access by two kind of person . local user (use that is in local network) and public user (user that access with domain name) How do i make my rail app to limit some of my url that access to controller for the public user? Using two rails with same mysql database but different port and port forward one only? Limit...

Is there an analog in Scala for the Rails "returning" method?

In Rails, one could use: returning Person.create do |p| p.first_name = "Collin" p.last_name = "VanDyck" end Avoiding having to do this: person = Person.create person.first_name = "Collin" person.last_name = "VanDyck" person I think the former way is cleaner and less repetitive. I find myself creating this method in my Scala pr...

How can I pass multiple attributes to find_or_create_by in Rails 3?

I want to use find_or_create_by, but this statement does NOT work. It does not "find" or "create" with the other attributes. productproperty = ProductProperty.find_or_create_by_product_id(:product_id => product.id, :property_id => property.id, :value => d[descname]) There seems to be very little, or no, information on the use of dynam...

I would like to use psql triggers in rails app? HOw do i use this line of code - createlang plpgsql database_name?

If i am gonna use postgres triggers in rails app, i can use execute { create triggger } for creating trigger in migration file. But where am i suppose to write these lines of "createlang plpgsql databasename;" ...

Set ActionMailer to use "foo.fr.erb" when I18n.locale is set to :en

I have this code: class Mailer < ActionMailer::Base def foo recipients "[email protected]" from "[email protected]" subject "Foo" body :var => "value" end end With two views in app/views/mailer: foo.en.erb foo.fr.erb When I use Mailer.deliver_foo, the view used to build the email is foo.en.erb sinc...

Ruby 1.9 slower than Ruby 1.8?

I have a Rails 2.3.8 app with an action that pulls a large amount of data from a database and renders it with anywhere from 300-600 partials (recursively rendering a tree-type structure). Benchmarking one request gives me response times of about 7 seconds. I thought that upgrading my Ruby version to 1.9 from 1.8 would give me a perform...

Why are the date fields in my rails object / model evaluating to nil when I can clearly see that they are not?

I'm using ruby 1.8.6 and rails 1.2.3 (ancient but I'm debugging an old app) A model called Payperiod has attributes begindate and enddate and after importing the db, the dates are all there (apparently) But in the console and in the app, the date attributes eval to nil. Why? Below is some code pasted from the console: pp = Payper...

Manipulating ActiveRecords using only a few attributes with Ruby on Rails

Hi, For caching matters, I'm caching an array of the attributes of the objects I need: friends = [{:id => 4, :name => "Kevin"}, {:id => 12, :name => "Martin"}, …] Is it possible to have a list of Users using this array, so that I can use Ruby methods? For instance, I usually get a list of non-friends with this: non_friends = User.al...

howto spec not all models

I know rake spec:models to spec all models. Is there a way to spec only one model, or only a given collection of models? Something like this would be desirable: rake spec:model user or with a collection of models rake spec:model user role order BTW: Brian Hogan wrote created something similar (see here) but maybe there is some...

No dispatch.fcgi on ruby app

Hi I'm trying to interface redmine to IIS 6. It works fine under webrick. So I tried to create a new rails app to reduce the complexity, but that doesn't create the dispatch.fcgi file in the public folder, which leads me to think that my RubyIIS setup is wrong. What am I doing wrong here? I have no idea about ruby or rails, so need ...

How to work with different versions of rails project at once?

With git is possible to jump back to early versions of a project. Now, to work with these early versions, they depend often on old versions of libraries. Is it possible to circumvent problems like these: /opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/rails/gem_dependency.rb:220:in `specification': can't activate haml (= 2.1.0, runt...

Create join table with no primary key

I have two tables with a many to many relationship that I am using has_and_belongs_to_many to define the association. class Foo < ActiveRecord::Base ... has_and_belongs_to_many :bar ... end class Bar < ActiveRecord::Base ... has_and_belongs_to_many :foo ... end I also have the class defined to represent the join table cl...

ruby socket log server

We use the default ruby logging module to log the errors. We use the delayed_job which is using many worker processes. So we could not manage the log files. We need the ruby based log server with rolling file appender and archive facility so that we can push the logs to the log server and let the log server to manage the logging task. ...