ruby-on-rails

Cucumber errors suppressed (not displayed fully)

I just installed cucumber, and I tested it. I got the following error: teefcomp:cucumber-intro teef$ cucumber features/manage_users.feature Using the default profile... F----F Failing Scenarios: cucumber features/manage_users.feature:6 # Scenario: User List 1 scenario (1 failed) 4 steps (4 skipped) 0m0.029s It seems to be suppressin...

What is the best way to add content to a template?

I am trying to find a way to add content to a div that is defined in my application.html.haml file from individual view files. The reason I want to do this is because I have a sidebar that is always present and is defined in the template, but I would like to have content specific to each page included in the sidebar. Would this be done b...

Rails controller/routing question

I am new to RoR and I cant get one of my rotes to work, not sure whats going on? I have defined a route in my routes.rb file, somthing like this... map.connect 'myurl/:someid/:start/:limit', :conditions => { :method => :get }, :controller => 'mycontroller', :action => 'get_data_list' # method defintion in mycontroller def get_data_lis...

Creating a site badge or widget in rails: Problem calling the second script

Hi all, I'm doing my best to create a site badge or widget for my site, which is a rails site. Essentially it's a site where users post content that they've created and other who like that content can make a donation to express their appreciation for it. I asked a similar question a while back about how to create a widget, but that wa...

What is this inside an erb template [Rails]

I'm seeing code like this inside of an erb template: <% hook :admin_footer_scripts do -%> What exactly is hook? is it a standard method within ActionView? ...

ActiveRecord Table Aliases

Does anyone know if it's somehow possible to setup an alias for an ActiveRecord table join? Something like: User.find(:all, :alias => "Users as u", :joins => "Friends as f", :select => "u.id,f.name") Any ideas? ...

ruby class declaration question

in ruby you can have: class ApplicationController < ActionController::Base before_filter :require_login end i just wonder what is before_filter? it's a method from ActionController::Base? and what will happen if i create an object of ApplicationController? The before_filter method will be run? thanks! ...

Understanding this Rails helper

This is a helper method I found in the ruby on rails application spree commerce. I'm trying to better understand what's going on here, particularly with the capture() method on line 12, which I've never seen before. If there is a block given, it captures it, otherwise there is no content. But where does capture() come from? what is it d...

'rake spec' works, 'spec spec' doesn't

When I added my first gem dependency to config/environment.rb, (will_paginate), I'm encountering an error when running rspec as follows: nik$ spec spec/ Missing these required gems: will_paginate You're running: ruby 1.8.6.369 at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby rubygems 1.3.7 at /Users/nik/.g...

Rails 2.3.8 problem

I am running Ruby 1.9.1 & rails 2.3.8. Everything is installed fine as far as I can tell but when I run rake db:migrate I get this error: Missing the Rails 2.3.8 gem. Please gem install -v=2.3.8 rails, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VE...

Rails 3: 'The file type yml is not known' when trying to access basic _form.html.erb.

Hi folks, I'm trying to write up a very basic rails app, but any time I write up even the simplest form I get the following error: I18n::UnknownFileType in Posts#add Showing /home/john/Websites/sandbox/rails-messing/app/views/posts/_form.html.erb where line #14 raised: can not load translations from /usr/local/rvm/gems/ruby-head/gem...

Is there any performance difference between these two code examples?

The code below seems to do the same thing, but does one have better performance than the other, or they are the same? Thank you. Code 1: <% @posts.each do |post| -%> post.doSomething <% end -%> Code 2: <% for post in @posts %> post.doSomething <% end -%> ...

How to deal with authentication for a Ruby API wrapper?

I'm working on an API wrapper for Viddler, which will eventually be made public, and I'm trying to figure out the best way to deal with authentication/API keys, specifically with usage within Rails applications in mind. The easiest way to write the wrapper would be to just have the code create a new client each time, and the developer c...

gsub within before_validation method is zeroing out my value

I'm trying to remove dollar signs and commas from my form input (for example, $1,000.00 => 1000.00) I have the following following line in my before_validation method in my model: self.parents_mortgage = self.parents_mortgage.to_s.gsub!('$,','').to_i This is causing any number to be put through to zero out. Is there something wrong w...

Update some part of view(div) as progress of controller's action in Rails.

I have div tag named update_info in the view my_view.html.erb and update action takes several minute to complete in the controller my_controller.rb. I'd like to update update_info div tag every seconds as update action's progress. How can I do this? Is it possible update view from the action's loop? Or using Ajax?, if so, how can I ac...

How can I use declarative authorization without always keeping the user id as a param in the URL?

Declarative authorization seems to require params[:id] to do its validation and I want to use paths like /profile and /dashboard where the user is stored in the session and not the URL. But it breaks. Any ideas on how I can do this without hacking the gem itself? ...

Rails validation -- error is generated , but record is still saved

Hi, I have models order.rb , line_items.rb -- where line_item is belongs to order. I've added custom validations, as such an order should only have line_items all with same merchant_id My question is : it seems the validation is working fine -- i am able to get the error whenever it is violated, but "line_item" records are still saved i...

ERROR while running Sunspot solr search engine

i have installed sunspot search engine as mentioned in website http://www.linux-mag.com/id/7341/2/ every thing is installed correctly but it is showing error while starting a solr instance for sunspot when i run command "sunspot-solr start -- -p 8983 -d /home/sharath/data/solr/devp" it shows error "sunspot-solr: command not found" ...

What is the class of an association based on the foreign key attribute only?

Short: I have an foreign key attribute and want to know what is the class (or reference table) of that foreign key field. Context: given 2 tables: users(id, [other fields]) and issues(id, user_id, assigned_to, [other fields]) Here is my active record of Issue (irrelevant parts are extracted) class User < ActiveRecord::Base ... end ...

[Rails] How to reload a div using render(:update) and replace_html?

How to reload only the div id on a page? I just need to reload a certain div. in my controller I have def mycontrolleraction ... render(:update) do |page| reload_only_the_div('adiv'), :controller => 'my_controller' end end Is this possible? ...