ruby-on-rails

Find number of distinct values in a specific column in a Rails find

I am doing a find in Rails model as follows: @jobs = Job.find(:all, :conditions => ["job_id = ?", params[:id]]) The result of this query also brings back data from an associated model JobResponses (there are multiple JobResponses for each Job record). Once I have the JobResponse results I am calculating a number of different averages/...

Rails add_test_data migration

Hey Guys, Just working through the Agile Web Development with Rails book and near the closing chapters of the book I had to rollback the db a few times using db:migrate VERSION=0 followed by the db:migrate command. However upon bringing the database back from the ground up, the add_test_data migration fails to add the test entries to th...

authlogic auto_register feature using my options

I have auto registration working with authlogic using gaizka's version of authlogic_openid which I found on Github since pelle's original addition of the feature seemed to cause issues. http://github.com/gaizka/authlogic%5Fopenid http://stackoverflow.com/questions/1476953/using-authlogic-to-auto-create-users-bypassing-explicit-user-r...

DRYing my views, helper / method / something else?

Have written some RoR sites in the past, but never bothered too much at DRYing up my views as it's only ever been me looking at the code. Just starting a new site, that is likely to be a collaboration, and need help I call this line multiple times in my views, and from multiple places. <%= Person.find_by_id(rider.person_id).name %> ...

Fetch data from multiple tables and sort all by their time

Hello, I'm creating a page where I want to make a history page. So I was wondering if there is any way to fetch all rows from multiple tables and then sort by their time? Every table has a field called "created_at". So is there any way to fetch from all tables and sort without having Rails sorting them form me? ...

In Rails, how do I assign an instance variable from within define_method and expose it from controllers down to views?

Hi there, I'm trying to write an action generator for my Rails apps (probably the most basic form of metaprogramming you can get. My question is, how do I assign an instance variable that is available in views? To me, the code would look like this: ApplicationController < ActionController::Base def generate_custom_action define_...

is the session hash in rails depending on the user's browser settings?

my rails app provides additional data through the session hash. while testing it in different browsers - including ff 3.5, safari 4 and iCab (which i am using because of its harsh security guidelines) - i found out that even in the app's log the session hash looked different - the only thing the iCab session contained was the session_id...

jruby 1.4 webrick logs in rails

I just upgraded jruby to 1.4 and I notice when I run my rails app that I get all kinds of logging spam now. Has anyone had experience with this? I'm not sure if it's a jruby thing, or if they've change the version of Webrick (i can't remember the version being run before) but I have a log line for every static file it loads. The wor...

Best practices for iterative development of views

When your application has a view that is only accessible after submitting another form (think signup screen, a shopping cart checkout, or a wizard-like interface), what's the best way to work on the successive views without having to click through all the preceding steps? Let's say we're working on the second or third step of a build-a-...

Recoding a Podcast Website - What should I use?

OK here is the deal. Me and some buddies are doing a Podcast(for over 4 year now) and in April we relaunched the site, that included a new Backend. Since I only had 2 weeks back then for getting everything to work, I decided to create something from scratch so everything fitted precisely our needs. The whole thing was written in Python b...

system and fork calls are blocking the port 3000

I am using ruby 1.8.7 and rails 2.3.4 . I am developing a plugin so I don't have too much of leeway. In my controller I need to invoke a rake task. The rake task will take longer to finish so I am following the approach mentioned in Railscast which is system "rake #{task} &" This solution works great and everything is fine. I know th...

ruby http error - wrong Content-Length format

hi, I have the following code url = URI.parse("http://localhost:3100/tasks/#{id}.xml") http = Net::HTTP.new(url.host, url.port) # Make request response = http.start do |http| http.get(url.request_uri) end Whenever this code is run, it returns the following error Net::HTTPHeaderSyntaxError in TasksController#show wrong Content-...

Is RJS evil and why?

I heard a bunch of rails developer saying that RJS is evil. I've never used it since I always managed to do what I wanted using classic javascript or jquery so I didn't pay attention. Now I'm getting into some legacy code and there's RJS all over the place. So... is it true? What are the drawbacks/advantages of using RJS? ...

Views in Ruby on Rails, enabling submit_tag with javascript

I have an html.erb file which includes the following <%= submit_tag "Locate", :disabled => true %> I also have <%= text_field_tag 'locationPOS', "", :disabled => true %> which has its value updated when the user click on the google map present on the page (from a separate javascript file) by locpos.value = place.address; I would li...

(Rails) Maintaining Javascript functionality in dynamically generated content...?

Hi All, I'm looking for a quality mechanism to add sorting to dynamically generated tables. My visual setup is very simple. On the left side I have a menu with series of items to select from (charts, graphs, images, tables, etc.). Once an item is clicked, it will show up in the "dynamic-content" div on the right side of the page. T...

Using a method in seeds.rb in Ruby On Rails

I am trying to add a method to my seeds.rb so that I don't have to write a bunch of verbose code. However, depending on the placement of the create_deliverable method I get one of two error messages when running db:setup. When method is before call rake aborted! private method 'create_deliverable' called for # When method is aft...

Are there any ActionMailer security gotchas

I know that in PHP I need to validate/massage any input that goes into an email header (eg the recipients email address). Is there anything I need to be aware of with ruby on rails/ActionMailer as regards email security? ...

sphinx is returning stale results

Environment: Memcached, Rails 2.2.2 + cache_money, Sphinx + thinking sphinx The following yields stale results: - add a record; mysql contains the correct data - the record is probably cached in memory at this point - re-index sphinx - sphinx returns the proper result with the correct data - edit the record - the cache is invalidated p...

Using includes / joins

I have a Proposal model and a Signature model. Proposal has many signatures and Signature belongs to proposal My relationships work fine when I select a single Proposal, but when I do a Proposal.search and return multiple proposals, I can't access signatures. I want to sort my proposals by signatures count, so I tried this: Proposal....

Nested object models, loops in view and erronous input makes views loop weirdly

Hello! I've been googling and testing on this problem for quite a while, but can't find an answer. I have a site, that servers surveys uploaded by admins. These surveys belong to surveycycles and answers belong to answerings. class Answering < ActiveRecord::Base has_many :answers accepts_nested_attributes_for :answers, :allow_destr...