ruby-on-rails

How do I set a filter that will reject existing records when using accepts_nested_attributes_for

I have a Message and Source model related as follows: class Message < ActiveRecord::Base has_many :sources accepts_nested_attributes_for :sources, :allow_destroy => true, :reject_if => proc{|s| s[:href].blank?} end class Source < ActiveRecord::Base belongs_to :outgoing_message validates_presence_of :href end When I submit my ...

How could I 'hide away' a complex group_by clause in Ruby?

In a Rails 3 app, I'm running a somewhat complex group_by and am curious if I can hide it away elsewhere, much like one can hide away ActiveRecord conditions in a scope. I realize group_by is an operation on an Enumerable, so scopes don't apply here, but my question is if there's a way to create a shorthand for this in a comparable way: ...

Page load time, when in RoR lifecycle do you start/stop a timer to get this stat?

Page load time, when in RoR lifecycle do you start/stop a timer to get this stat? I know I can create a before/after at the controller level, is there anything higher up in the chain that I get start/stop this timer? I want to get timings for a production release also, not just development mode where things are always slower. ...

How to change Rails 3.0's default log path?

I have to change my rail application's default log path because of my company's internal software deployment process: basically my rails app ends up on a read-only location, and I need the log files written in a directory "made for this". With Rails 2.x we used to add some black magic in our FCGI script to force that in when deployed on...

How to do find() with includes() in Rails 3

I'm trying to do something like this, but it's not working. How would i do this in Rails 3? Student.find(12).includes( :teacher ) ...

Is there a benefit to creating a very generic data model for a Rails 3 Project?

A Product can have lots of things said about it, I'll call them Properties. It can have a brief description. But that description can be in multiple languages. Likewise, it can have multiple Prices, some which are specific to Customers. Given the following data: Product: identifier: 123-ABC Price: value: $1.25 currency: ...

Are there any fix yet on the Gemfile/bundler issue with Heroku?

I have been experiencing a problem that several Railers have been experiencing so far when pushing to Heroku. I have tried several fixes so far including the one stated here, but to no avail. I need help, any help would be appreciated. ...

default_scope breaks (update|delete|destroy)_all in some cases

Hello, I believe this is a bug in Rails 3. I am hoping someone here can steer me in the correct direction. The code posted below, is purely for illustration of this problem. Hopefully this does not confuse the issue. Given I have a Post model, and a Comment model. Post has_many Comments, and Comment belongs_to Post. With a default_scop...

How to get result of the previous action

Hi Inside rails console you can get the result of the previous operation with _ Is there any way to do such a thing inside ruby program? ...

Rails multi select defaults

I am working on a script that allows for an admin to assign multiple languages to a user. I have my multi select working like so: <%= fields_for :users_languages do |u| %> <div class="field"> <%= @lang_list.inspect %> <%= u.label :Assign_Languages %><br /> <%= select_tag :language_id, options_for...

ActiveRecord doesn't set a datetime field

I have a datetime field called time in my MotionRecord model. I try to set it using this command: MotionRecord.create({:time=> "2010-10-15 15:10:24", :chart_id=>1}) Oddly enough this results in the following input: <MotionRecord id: 1, time: nil, chart_id: 1> I'm not sure what I am doing wrong. Edit: This is my model. class Moti...

"WARNING: Can't mass-assign protected attributes"

I have used RESTful techniques to generate a model (in fact, I am using Devise gem, which does that for me), and I have added new fields called first_name and last_name to the model. Migration went fine. I added attr_accessor :first_name, :last_name to the model and expected it would just work. But when I try to mass-assign new instances...

What kind of jobs are there for a small web dev shop?

Sales guy here (duck) has a 3 programmers strong team at hand and asks what kind of clients he could provide them with. They love RoR but are not shy of other technologies. They want to do web development as a team. Now the question is what kind of projects can they realistically tackle? I researched the market and it seems there are...

Rails and created_at

Hi all! I do: Order.find(:all, :conditions => "created_at>='#{DateTime.now.year}-#{month}-1' and created_at<='#{Date.new(DateTime.now.year, month.to_i, -1)}'") That is working fine except that everything created on the last day of the month is not included. Created_at might contain: "2010-09-30 18:34:09". That is NOT less than or equ...

How can my app parse twitter (xml or json) response [200 or 401]?

How can my app parse the Twitter response when someone using a curl command, like this: curl -v -H 'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json' -H 'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/", oauth_consumer_key="**jhtmLUypg82g", oauth_signature_method="HMAC-SHA1", oa...

named_scopes and all

I'm on Rails 2.3.5. Inside my application a user could book one or more time slots for a specific day. I've defined this named_scope in my Slot model: # day time slots named_scope :for_day, lambda { |day| if !day.blank? { :conditions => ['day_of_week = ?', day] } end } I use that to retrieve all the "time slots" av...

check if Tag exists before adding it to array

I have the following code: unless params[:search_tags].nil? logger.debug "Going through tags now #{params[:search_tags]}" params[:search_tags].split(",").each{ |tag| tag.strip! tag = '%' + tag + '%' tags = Tag.find(:all, :conditions => ["name LIKE ?", tag]) if tags.nil? || tags.empty? # I'm searching for something th...

High traffic rails perf tuning

I was attempting to evaluate various Rails server solutions. First on my list was an nginx + passenger system. I spun up an EC2 instance with 8 gigs of RAM and 2 processors, installed nginx and passenger, and added this to the nginx.conf file: passenger_max_pool_size 30; passenger_pool_idle_time 0; rails_framework_spawner_idle_time 0;...

How to save multiple initialized record with one save.

Take it as example. new_array = [] Country.all do |c| g = c c = c.clone c.country_name = "kkk" new_array << c end At this point my new_array containing multiple records .. How may i store all the values with one save or create ? Any other better way ? ...

Weird country_options_for_select in Rails

I currently have my index.html.erb showing the following code. <select name="country"> <option>All</option> <%= country_options_for_select('All') %> </select> But the result of the page becomes like this in the html source: <select name="country"> <option>All</option> &lt;optionvalue=&quot;Afghanistan&quot;&gt;Afghanistan&lt;/opt...