ruby-on-rails

postfix and rails : error 'hostname was not match with the server certificate error'

I am trying to setup Postfix with SMTP and with TLS on to be used by rails 2.3.10 app. email.yml settings are as follows: my mail server is domain1.com production: :enable_starttls_auto: true :address: domain1.com :domain: domain1.com :port: 25 :authentication: :login :user_name: username :password: passwd Postfix is co...

Rails 3 Query Interface: using associated models

I'll use the generic blog example. class Post < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :post end When querying Post, how do you access its associations (i.e. :comments)? This should be the easiest thing in the world, but I haven't found any documentation on it. Even http://edgeguid...

each_with_index desired column output Rails

<% source.strains.each_with_index do |strain, j| %> <% if (j == (source.strains.size - 1)) %> <font size="3">Strain <%= strain[0].appendix %> </font> <% end %> <% end %> I need to get output as If j value is last one of a loop, then i need to print first value of loop (j[0]). Kindly suggest me or correct abo...

What is wrong in this ruby statement?

I am trying to do something when I am connecting to my own server(local). I found request.env from the website, so I am using that array to compare my IPs. <% if request.env['HTTP_HOST']!="127.0.0.1" puts request.env['HTTP_HOST'] else puts "its Local!" end %> When I run above in rails3, I get nothing printed... I am new t...

using geokit or other ruby gem to calculate the center of a series of geo coordinates.

I've been using the geokit and geokit-rails gem for rails for awhile but one question I haven't found answered is how to find the calculated aggregate center for a collection of points. I know how to calculate the distance between two points, but not more than 2. My reason is, I have a series of points all in the same city... all thing...

Adding translations for the models in the Rails application

Hi , I am new to ROR. I am trying add translations to my application. I have added translations for the controllers. Where to add translations for models as i am not having any /config/locales -> models folder ->en.yml file . In the model i am having lines like validates_presence_of :name, :message => "Name cannot be blank!" If i...

mongoid querying problem

I have a Three documents, here is a sample with fields not shown class College include Mongoid::Document references_many :students,:stored_as => :array, :inverse_of => :colleges end class Student include Mongoid::Document embedded_in :college, :inverse_of => :students embeds_one :mark end class Mark include Mongoid::Docum...

OmniAuth & Facebook: certificate verify failed

I've followed Railscast #235 to try and set up a minimal Facebook authentication. I've first set up a Twitter authentication, as done by Ryan himself. That worked flawlessly. I then moved on to adding a Facebook login. However, after authorizing the app the redirect to /auth/facebook/callback fails with: SSL_connect returned=1 errno=0...

Problem rendering vanilla JavaScript in Ruby

Hi all, In My controller I am trying to render vanilla JavaScript but am getting an unexpected result. This is the code class UploadController < ApplicationController def index render :file => 'app\views\upload\uploadfile.rhtml' end def uploadFile render :js => "alert('Hello Rails');" post = Da...

Rails to_xml, use xml attributes instead of child nodes

I've been playing around with rail's to_xml, trying to create a really simple rest interface for a project i'm working on. So far, i've come up with cards = Card.all(:conditions => {:racedate => Date.today.to_s}) render :xml => cards.to_xml(:include => {:races => { :only => [:id, :number, :race_time, :name] } }, :skip_types => true, :...

What's the best way to connect to SQL Server from Ruby on OS X?

I need to let my Rails app connect to a MS SQL Server database and do a simple query to do a lookup. The main DB for the app is MySQL. It just needs to do this SQL Server thing on the side. What's the best way to do that? I could write an entirely separate app in Java that connects to the DB and dumps some XML data to the filesystem fo...

In Rails, I thought once the "Foo.all" is executed, then "models/foo.rb" is loaded?

In Rails, if I create a scaffold foo, and do rake db:migrate, then now app/models/foo.rb is created. So if I go to script/console (or rails console for Rails 3) and type $".grep /foo/i it is empty. $" is the loaded files. So foo.rb is not loaded yet. Now I do a Foo.all, and foo.rb should be loaded now. But when I repeat ...

Searching with Join in Rails 3. Please help!

Hello! I am developing a small application in Rails 3. In this application users can be connected to each other. I am mainly using two tables to store user data and relations. I want to search these tables with either firstname or lastname to get the contacts of a user. Table ONE - Profiles In this table I am storing Firstname, Lastna...

Easiest way to "goto source code" for Ruby/Rails

As a Ruby/Rails non-pro, I often want to check out the code for a rails method to see how it's implemented... For example, I was using "form_for", and I wanted to check out the code to see how it works. The slightly lame way I did this was to just google "rails form_for" which takes me to http://api.rubyonrails.org/classes/ActionView/H...

Why is this basic Rails 3 route not working?

I've just upgraded to Rails 3, and decided to take it for a whirl with a dummy/sandbox app. The strange thing is I can't seem to get any routes to work! Here's my problem: [cobychapple@shiva:Dev]$rails new TestApp create create README create Rakefile ... [cobychapple@shiva:Dev]$cd TestApp/ [cobychapple@shiva...

Please help me make this Rails code more dry. I must be missing something very obvious

This rails validation code is so ugly, and there must be a better way to do it. The short story is my user is inputting data from test results. Each specific test has 4 measurements. Usually the user inputs all 5 tests (20 measurements), but it's not always required. I just need to check that if a tester started inputting data for a ...

Is the request timing information in rails accurate?

In a rails (2.3.8) app, my server log in development mode shows lines like these: Completed in 265ms (View: 212, DB: 8) What accounts for the missing 45ms? Even when repeating a request that does hardly anything, the timing information often reads: Completed in 14ms (View: 1, DB: 1) Is the remaining time anything to do with framew...

SQL request to find the n last records of each one of a user's friends

Hi, I have a User model which has friends (User.friends with a user_id/friend_id join table called followings). Each user has events (the events table has a user_id column). For an activity feed, I want to get an array with the last 20 events of the friends of the user. Right now I'm calling the last 20 events for each friend, sorting ...

Rails/ActiveRecord: Syntax for "or" conditions?

Hi folks, Just trying to figure out how to write "or" statements in activerecord conditions without resorting to raw sql - I assume it can be done, but google isn't helping much. So, to give an example, suppose there's a model "Author" with a one-to-many relationship with 'Books' and a many-to-one relationship with 'Publisher'. How wou...

ActiveSupport requires Ruby version >= 1.8.7 on Ubuntu

Hi, I'm currently setting up a new server, and started off with an Ubuntu 8.04 image with a version of Ruby and Rails already preinstalled (I thought it would be easier), and after getting my app running (with a few gems installed), the command line is throwing a wobbly, and trying to install the "Paperclip" gem, is giving the following ...