ruby-on-rails

confusion about accepts_nested_attributes_for

Somehow, I was under impression that accepts_nested_attributes_for will let me populate child object through parent: person.update_attributes person_hash but in practice I ended up doing this: person.address.update_attributes person_hash[:address] person_hash.delete :address person.update_attributes person_hash Now, http://guid...

Ruby on Rails: How do I run a Cucumber task inside a rake file?

Currently, I have this Rake::Task['FEATURE=features/Authentication.feature cucumber'].invoke but id doesn't work.. says Don't know how to build task 'FEATURE=features/Authentication.feature cucumber' but when I do rake FEATURE=features/Authentication.feature cucumber that works... =\ ...

How do I specific creation of a link without params in rails?

In my view, I want to use link_to_unless_current create a link to "/payforms" when I'm on page. However, when I pass parameters, such as, "/payforms?submitted=true", for example, the function still thinks I'm on "current" and the link is not created. Is there a way for me to check if there are no parameters? <%= link_to_unless_curre...

automatically including a plugin/gem's module in rails

I have a gem that I'm working on that contains a module that I'd like to be automatically included in my Rails app. For now, I've put the following: config.after_initialize do include MyModule end I'd like to not have to include this in the instructions for my app. It would be great if someone could install the gem/plugin and have t...

activerecord-sqlserver-adapter on Ubuntu

I followed the instructions found here to get my rails app to communicate with SQL Server on Ubuntu 10.04 http://wiki.github.com/rails-sqlserver/2000-2005-adapter/platform-installation-ubuntu-2 All the tests documented there have passes except the when I try script/sconsole I was able to make a db connection in irb In my app I have a ...

how is this table updated if there is no model file?

I'm trying to manually update a db in Spree, but it has no model file. I want to know how to CRUD into the option_values_variants table. The code uses James Golick's Resource Controller, but I want to do it without. models/option_value.rb class OptionValue < ActiveRecord::Base belongs_to :option_type acts_as_list :scope => :option...

Capturing Rails 3 Multiselect Input Params

I have a multiselect form control (fig. 1). When I select more than 1 value, Firefox sends both values (fig. 2). But only the last value gets sent as a input value to my controller (fig. 3). How do I get all those values passed on to my controller? <form action="html_items/search" method="post" > <!-- Criteria --> <div styl...

Rails Time.now, shows time server started and not actual time.

I've seen this problem before but I'm not sure how to solve it. Say I have: class Notification < ActiveRecord::Base scope :current_notifications, where("starts_at <= ?", Time.now).where("ends_at >= ?", Time.now).limit(1) end So the scope is being calculated from the time that the server started, any thoughts on how to fix instances...

How can I set RAILS_ENV to production for all subsequent rake commands?

As a bonus how do I set this in a config, so that when I log into my production server I don't have to retype it. ...

Ruby on Rails: Is there a way to make blank form inputs submit nil?

Is there a way to make blank form inputs submit nil? Right now, I'm going through and in a before_save manually converting all "" into nil. This really doesn't seem very DRY, and I feel like I must be missing something. ...

git clone problem

i have create clone of project on local machine with git clone [email protected]:test/abc.git Now i want to deploy my project on my ubuntu server . so i have created a script which install git on my ubuntu server. And now i want to deploy my rails project on server. like git clone [email protected]:test/abc.git but i have not set ssh key ...

Are there any tutorials or guides for setting up an Apple Push Notification server in Rails (3.0)?

I've got an app that I am building in Rails 3 (and MongoDB using Mongoid). I want to be able to send Apple Push Notifications to iOS devices. I am aware of PRX's apn_on_rails and samsoffes' apple_push_notification gems, but they do not appear to work correctly in Rails 3. Are there any tutorials out there for setting up an APN server in...

ruby on rails concatenating two active records objects

I have two complex rails (AR) queries coming from two different methods that I sometimes want to concatenate. The data structure returned in each object is the same I just want to append one onto another. Here's a simplified example (not my actual code): @peep1 = Person.find(1) @peep2 = Person.find(2) Thought something like this w...

How can I access UrlWriter url/path generators from a model's class method?

I want to generate urls from a model's class method. I've done this before from an instance method by simply including ActionController::UrlWriter -- I tried including this in the instance definition scope and also the class definition scope, to no avail. class Foo < ActiveRecord::Base # only works for instance methods # include Act...

How to render HTML from a Rails instance variable?

I have an intstance variable I am passing to a view, @body. @body is a string with html in it. <%= @body %> renders the string, not the html. How do I render the html in the string? Possible? Thanks in advance! ...

Rails: Difference between List and Index

I appreciate this is an incredibly noob question, but having Googled multiple combinations of search terms I regretfully am still in the dark. These things can be difficult when one doesn't know and so obvious when one does. I have semi-home page where incoming customers can choose to see a queried list or do a handful of other things. ...

Managing conditional redirect_to in Rails

I have multiple user types in a system that shows each user different views and templates of the stored information, often based on whether they are logged in and what current_user.user_type is. As a result, I have lots of this: #controller @project = Project.find(params[:id]) if current_user.user_type == "Company" redirect_to :contro...

What's a good swiss-army framework for the next 5 years?

Basically, we want to use no flash, and eschew php where possible (for marketing reasons). Right now, I'm looking at Ruby on Rails and like what I see... but I'm not really a programmer, having working primarily with Wordpress, Drupal, and Joomla for the past 10 years. Our sites need to have a lot of custom apps built into them (video ...

Self-referential has_many :through with customized :primary key issue

I'm trying to emulate the twitter model in my Rails 2.3.8 app (ruby 1.8.7) class Connection < ActiveRecord::Base belongs_to :subject, :foreign_key => 'subject_id', :primary_key => 'user_id', :class_name => 'User' belongs_to :follower, :foreign_key => 'follower_id', :primary_key => 'user_id', :class_name => 'User' end class User < A...

How to make ActiveRecord's association collection methods private

Hi everyone, I need a way to make association collection methods (particularly the append <<) private. Here's an example: class Foo < ActiveRecord::Base has_many :bars def add_bar (bar) # does something extra first # but still also use the <<, ultimately bars.send(:<<, bar) end end Basically, i do not want any p...