ruby-on-rails

Displaying Posts by number of "vote" records in separate table

I am new to Rails so go easy. I have created a blog and also created the ability for users to indicate they "like" a particular post. The way I am implementing this is by using the post table and a separate table 'vote'. When the user clicks the "like" button it sends the record to the 'vote' table with a value of '1' and the particular ...

Rails Restful actions Index Put

I have frequently run into the situation where I want to update many records at once - like GMail does with setting many messages "read" or "unread". Rails encourages this with the 'update' method on an ActiveRecord class - Comment.update(keys, values) Example - http://snippets.dzone.com/posts/show/7495 This is great functionality, bu...

How could I implement a digital signature in an application?

I'm developing a software in Ruby on Rails that saves information about documents that requires fisical signatures. The idea is do it all digital including the signature. How could I do that? Do I have to save a hash in the database? EDIT: Well, I mean Digital Signature ...

RSpec in Rails: How to skip a before_filter?

Hello everyone, I am trying to test my controller and maintain separation of concerns. The first concern is "Who is able to execute which action?" I am using authlogic for authentication and be9's acl9 for authorization. But this should not matter, all my authorization concerns are handled in a before_filter. I am testing such a befor...

Running multiple sites from the same rails codebase?

I have a client that wants to take their Rails app that has been successful in one niche and apply it to another similar niche. This new instance of the app is going to start out very similar: all the same functionality, different logo and colors. However, if the new site is successful it will inevitably need significant customizations t...

How would I construct this join with a count condition in the joined table?

I'm trying to find the 'open' games, which are games that have a player slot open. Games are created with num_players, which represents the max player capacity for that game. Games have_many players. I tried the following Game.find(:all, :include => :players, :group => 'players.game_id', :conditions => ['players.count(*) < games.num_...

How to set Default format for activerecord fields of type string?

Here's an easy one: How do I go about setting the default format for a string field in ActiveRecord? I've tried the following: def phone_number_f "...#{phone_number}format_here..." end But I'd like to keep the method name the same as the field name. ...

Rails - RESTful Routing - Add a POST for Member i.e(tips/6)

Hello there, I'm trying to create some nice RESTful structure for my app in rails but now I'm stuck on a conception that unfortunately I'm not sure if its correct, but if someone could help me on this it would be very well appreciated. If noticed that for RESTful routes we have (the uncommented ones) collection :index => 'GET' ...

link_to issue with inherited Active Record class.

Here are the classes as I have them set up: class Stat < ActiveRecord::Base belongs_to :stats_parent end class TotalStat < Stat belongs_to :stats_parent end #The StatsParent class is just to show how I use the relation. class StatsParent < ActiveRecord::Base has_one :total_stat has_many :stats end For the Stats Cont...

accepts_nested_attributes_for not generating foreign key

I have a model class ServiceRequest < ActiveRecord::Base has_many :services accepts_nested_attributes_for :services ... end and the child class Service < ActiveRecord::Base belongs_to :service_category, :foreign_key => "wsi_web_serv_cats_uid_fk" belongs_to :service_type, :foreign_key => "wsi_web_serv_types_uid_fk" belon...

Nested Routes and Parameters for Rails URLs (Best Practice)

Hey there, I have a decent understanding of RESTful urls and all the theory behind not nesting urls, but I'm still not quite sure how this looks in an enterprise application, like something like Amazon, StackOverflow, or Google... Google has urls like this: http://code.google.com/apis/ajax/ http://code.google.com/apis/maps/documentat...

How do I convert coordinates to google friendly coordinates

I need to do this.. <coordinates_east>6'01.4</coordinates_east> <coordinates_north>45'05.5</coordinates_north> I need to convert to this google friendly format in Ruby!...please note that these are not the real converted numbers just an example of the format I think I need! <coordinates_east>45.46998</coordinates_east> <coordinates_n...

utf8 encoded urls in rails 2.3.4

Hi, I just upgraded Rails to 2.3.4. Before the upgrade rails was ok with international characters in urls, but it isn't working anymore. How do I get the following to work with rails 2.3.4: ActionController::Routing::Routes.draw do |map| ... map.connect 'ö', :controller => 'test' ... end If I change 'ö' to 'o' it works...

Method definition without a name in Ruby on Rails

I recently looked at sample code for a controller in a rails project which included a method definition in a class without defining the name of the method like so: def begin redirect_to :action => :buy, :PaymentAction => params[:paymentaction] rescue Errno::ENOENT => exception flash[:error] = exception redirect_to :controller => '...

highlight div or p after loading

Hello i need to highlight a div after my page is loading, i don't know if i should use a partial or something like that, the partial also has to have 2 variables disponible. Code to highlight after loading by 5 seconds: <div id="total_de_venta"> <% if @instalador.a_destajo? %> <div align="right"><b>Total de la venta: $<%= @venta.precio...

Converting degree/minutes/seconds to decimal degrees

I'm asking this question in a different way, another user let me know what I need to ask for, I'm basically looking to convert to "decimal degrees". The conversion of course must be accurate. I see javascript solutions out there like this javascript example. I need ruby. Maybe someone could write the javascript in Ruby and I can try that...

Ruby on Rails Internationalization

Hey, I try to make my config/locals organized in directories like the app directory. I can not get this to work... Here http://guides.rubyonrails.org/i18n.html says you have to activate this manually under config like this config.i18n.load_path += Dir[File.join(RAILS_ROOT, 'config', 'locales', '**', '*.{rb,yml}')] but when I try to us...

is Joyent Slingshot Abandonware?

I really liked the idea, seems something like a dream, and well we have been working with the source code found, but we really couldn't find anything recent, stuff goes far as 2007. Does anyone one know of an alternative?. Features needed: Run a Rails web app Sync up with production one ...

How do I setup a functional test to authenticate openid with authlogic?

I have a functional test that is supposed to call ROTS (Ruby Openid Test Server) to act as an identity. In my UsersControllerTest, I have the following: test "creating a user" do get :create, :user => { :username => "woot", :email => "[email protected]", ...

Authlogic, is it secure enough out of the box?

I've managed to setup authlogic, and quite nice it appears too. Is it secure enough out of the box? I haven't really configured it too much. I'm going to be using it on a school website where the headmaster basically logs in with username and password to edit notices on the website. So it needs to be secure, but it ain't a bank or an e-...