ruby-on-rails

push new element into array within hash

Hello, I have a hash which, I have keys that uniquely identify each element within the hash. And within each element, I have an array. So my question is, how do I put another element inside that array within the hash. {"Apple"=>[1, 5.99], "Banana"=>[5, 9.99]} I'm looping through a result set, and I'm a little bit lost how to add an...

Live Search / auto_complete + HABTM = possible?

I am attempting to add in a form field that should allow me to add a record into a join table. The table name contains the ids of the following: log_id node_id So naturally, my models is setup as follows: class Log has_and_belongs_to_many :nodes end class Node has_and_belongs_to_many :nodes end The objective is that when I crea...

Refactoring a simple method in my controller

I'm having a tough time deciding how to refactor this method in my controller. The idea is that (in this case) it graphs the users that joined (or were created) in the past two weeks. You might be wondering why I did the @graph_limit thing, and that is because I always want the day that has the most results to be the tallest bar on my ...

Problems with passing variables to a partial

I'm using the partial "infowindow" (app/view/tech/_infowindow.html.erb) to populate a google map marker using: new_marker = GMarker.new([t.lat, t.lng], :icon => icon, :title => t.summary, :info_window => (render_to_string :partial => "infowindow", :object => t)) but i'm getting a very odd error. When I simply put: <%= debug(infowind...

Formtastic set class and id of form

How I can set the class and id attribute for the form element through semantic_form_for ? <% semantic_form_for (@meetingsearch), :class => "new_meeting_search", :id => "meeting_search" do |f| %> gives me <form action="/meetingsearches" class="formtastic meetingsearch" id="new_meetingsearch" method="post"> ...

date_select Ruby

How do I extend the range of the date_select in Ruby? It only goes as far as 2005 and I'd like to use it for the date of birth. ...

authlogic - cause for unsuccessful session creation and no error messages (with formtastic)

Hi, I have 2 questions about authlogic: 1 - how to get cause of unsuccessful session creation (for example - not confirmed, blocked, wrong pass etc) to use it in app logic (route to another page for confimation, or re-enter pass etc)? 2 - question about integration formtastic and authlogic. How to show error messages on session creatio...

Why does ActiveRecord has_many use delete_all instead of destroy_all?

I have a model which has many children. I was setting/removing the children as such: mymodel.children_ids = [1,2,3] mymodel.save #add the children mymodel.children_ids = [1] mymodel.save #remove children 2,3 This works just fine, but I just realized that none of the callbacks (i.e. after_destroy) are not being called on the children m...

Ruby testing: block vs. method

As I've been writing test suites for a Rails app, I've noticed that there are two different ways to create tests, a test block and a regular method: test "the truth" do assert true end vs. def test_for_something_else assert true end Is there any difference between the two testing structures? When should I use one over the othe...

Git hash as RAILS_ASSET_ID. Where to cache?

Hi I want to use the git hash of files as asset id. For that I created an initializer like below. require 'grit' module ActionView module Helpers module AssetTagHelper def rewrite_asset_path(source) asset_id = rails_asset_id(source) if asset_id.blank? source else "/s/#{asset_id}" ...

rails state_machine pattern for credit card processing

I'm using the rails state_machine plugin (looks better than aasm) - it looks great - however, I've implemented it for a credit card processing system I wrote and it looks a bit strange... the code looks very un-DRY... I wonder if anyone can cast a quick eye over it and let me know what they think. In particular, to me the bits that does...

Share the last Tweet on a webpage

Hello, I have a website with a database of users and I would like to allow them to display on their profile page their current tweet message (if they have a Twitter account). After searching, I had seen this tool: http://juitter.com It seems to be a little bit complex for just my needs. I am working with Rails. Do you know a tool as s...

Passing options in autospec with Cucumber in Ruby on Rails Development

I always run autospec to run features and RSpec at the same time, but running all the features is often time-consuming on my local computer. I would run every feature before committing code. I would like to pass the argument in autospec command. autospec doesn't obviously doesn't accept the arguments directly. Here's the output of autos...

Rails lib includes

Hello I have a puzzling issue regarding modules defined in the lib dir I have two files #lib/authentication.rb module Authentication end #lib/test_module.rb module TestModule end In my application controller I have class ApplicationController < ActionController::Base include Authentication include TestModule end ...

Rails: What is the best way to seperate two very similar views?

I have a controller that has two actions: "show", "show_modify". These have very similar yet slightly different views, i.e show_modify has different div classes, has extra links/buttons and so on. From what I've seen there are a few ways to approach this in rails: Make one template for the two and just add conditions inside: <% if par...

How to let the page reload specify div in RoR?

I modify my RoR application to calling a create.js.rjs after created an item. I want to reload a specify div in my page after I create an item, how can I do that? When my div have a ruby object like this: <div id="categoryList"> <% @categories.each do |category| %> <%= content_tag(:dt, category.name, :class => "menu-table")%><%...

no test for session key if sent by application

Hi, I'm writing a non browser application using rails as server. As I understand, I need to add the received session key to any successive request. If logged through a browser, it is indeed checked as deleting the cookie during a sesion will fail session test for any request senf afterwards. However, in my application, I can send any ...

How to find polymorphic relation

class Item < ActiveRecord::Base belongs_to :rulable, :polymorphic => true end class foo < ActiveRecord::Base has_many :items, :as => rulable end class bar < ActiveRecord::Base has_many :items, :as => rulable end What is the best way to find items belonging to a foo? I'm currently using something like this: f = Foo.find 1 Item.find_by_...

beginner question starting with RoR w/ postgreSQL

I have not done much RoR development. Most I've done is played around with it or went over few chapters in AWDR book. Now, though, I'm starting to do a real project in Rails and one of the client requirement is that they want the DB to be PostgreSQL. I know that rails comes with its own SqlLite. I am wondering what is the best option...

Rails classes reloading in production mode

Is there a way to reload ruby model in runtime? For example I've a model class Model def self.all_models @@all_models ||= Model.all end end Records in this model are changed very rarely, but then they do, I don't want to reload whole application, just this one class. ...