ruby-on-rails

How to skip before filters for json/xml requests in rails

I found a way to skip before filters based on the format, as seen below, but I'm wondering if there is a better way since this clutters things and isn't very DRY. before_filter do |controller| :current_cart unless controller.request.format.js? end If I don't do this, json requests fail because the current_cart method, and other meth...

Unknown Attributes on nested form in Rails

Hi all, I'm having trouble getting my InventoryItem to accept nested attributes which is strange. In my script/console, I did the following: >> InventoryItem.create!(:name => 'what', :image_attributes => [ {:image => File.open("/home/davidc/Desktop/letterbx.jpg", "r") }]) ActiveRecord::UnknownAttributeError: unknown attribute: image_a...

Ruby variable scope question -- alternatives to class-level variables for class_eval?

I have a question about best practices for Ruby variable scope using class_eval. In the below code snippet, in the class_eval block, the local variables first and second are undefined. def parent_method(opts={}) first = opts[:percent] second = (10 * first).to_i SecondClass.class_eval do def second_method; return {:...

Ruby on Rails: f.select: how do I remove the label?

f.select :field, [options] how do i get it so that it doesn't show the field name next to the box? ...

Deploying Rails 2.3.x with bundler and capistrano

We are looking to shift to bundler for deploying internal applications. We currently use capistrano for deployment using git for SCM. After googling extensively, I have found about 20 different ways to incorporate bundler into a rails 2.3.x application - but much of that information is out of date. currently we freeze gems to the appl...

Rails helper "Collection Select"

I have the exact same problem as this guy , since no one has answered, I decided to repost: I have been trying to implement this jquery plugin to my app.I need help trying to output something like this <select name="user[university_id]" id="user_university_id" class="selectable"> <option value="1" title="uni1">Uni1</option> <op...

has_and_belongs_to_many query works in one direction, fails in the other

I have: class Service < ActiveRecord::Base has_and_belongs_to_many :staffs and class Staff < ActiveRecord::Base has_and_belongs_to_many :services With the intermediate table services_staffs with columns services_id and staffs_id The following query succeeds: Staff.find( :all, :conditions => "service_id = #{service_id}" ) B...

Begin Rescue not catching error

I'm using some ruby code wrapped in a begin - rescue block but somehow it manages to still crash. the block of code looks like this: # Retrieve messages from server def get_messages @connection.select('INBOX') @connection.uid_search(['ALL']).each do |uid| msg = @connection.uid_fetch(uid,'RFC822').first.attr['RFC822'] begin...

Does rails store data relationships in the database?

When using relationships in rails are they stored in the database so all foreign keys are stored in the tables and such like or are all relationships controlled via the software? Thanks in Advance Dean ...

Limit Ring server to localhost only. RingFinger.new('localhost') apparently doesn't work

Am using RingyDingy. Have altered call to Rinda::RingFinger.new to Rinda::RingFinger.new('localhost') in ring_server.rb and in ringy_dingy.rb, but still get, intermittently, attachments to like named services on my compatriots (in the same lan segment) which causes things to disappear trying to run on their machine (or on mine from the...

Problem with a query with associations and "strange" select

Quick question: >> Group.first.resources.joins(:tags).group("tags.id").select("tags.id, count(*)") => [#<Resource id: 1>, #<Resource id: 2>, #<Resource id: 3>, #<Resource id: 4>, #<Resource id: 5>] This results in the following (correct) query: "SELECT tags.id, count(*) FROM "resources" INNER JOIN "taggings" ON "resources"."id" = "ta...

Are there advantages to using foriegn key constraints when working in an active record framework like ruby-on-rails?

I'm moving back into full time web development after a 5 year hiatus. My previous experience (no active record or MVC) tells me to be very thorough with my database schema. Foreign key constraints, unique indexes, etc... can really help out when your writing spaghetti code. Does the community still find these useful when working in an...

Can I render a haml template with Ruby on Rails metal?

I have metal working (thanks to Railscasts), but I have a haml template that I want to render instead of just plain text. Apparently you can render ERB , but I don't see any place to do the same with haml. Is it possible or will I just have to live with using the plain rails routing if I want to continue using haml? Thanks! ...

How do I use link_to_remote with a form as the remote URL?

I want to render a form (fields and includes a submit button) when using link_to_remote -- the form appears via an ajax call. I'd like that form to behave as any other form would (it's a basic New Active Record) form, nothing fancy. Upon submit, though, I'd like the original parent page to remain static without refreshing and, instead ...

Model inside a subfolder within models folder.

I'm using Ruby on Rails 2.3.8 and I'd like to know how to organize models in subfolders so Ruby can recognize them. ...

Delayed_job custom failing assertions?

Hey all, I'm using delayed_job for a priority queue. I was wondering how do i define what a failed job is? Thanks. ...

Plugin/Gem to get Rails 3 style UJS in Rails 2.3.x?

I have a new application starting that's using Rails 2.3.8 for stability concerns and gem compatibility, however we'd like to begin being conscious of Unobtrusive JavaScript by implementing the Rails 3 style UJS in this application. Is there any existing plugin/gem that backports this feature? We are currently using the jrails gem to s...

Ruby on Rails: accessing form elements with javascript

Hello! I have a form with a set of links and hidden inputs like this: <div><%=link_to '&darr;', {}, {:href =>'#', :onclick => "return moveDown(#{photo.id});"}%></div> <%= photo_form.hidden_field :position %> How do I change input value when link is clicked without hard-coding input ids on client side? i dont want to use selector...

Validating a self-referential association doesn't link back to the original instance in rails

I have a many-to-many model, following the example in this great railscast My model links authors to each other. I'd like to validate that an author cannot friend himself. I know I can handle this at the UI level, but I'd love to have a validation in place to prevent a bug in the UI from allowing it. I've tried validates_exclusion_of, b...

Getting an ActionController::InvalidAuthenticityToken for my XML

I am working with a third-party API. That server is supposed to POST back to my URL. My URL is: http://www.mydomain.com/teleku/playvoice.xml The controller has some logic, but basically contains a respond_to do block and the corresponding view is a very basic xml builder. However, I get the following error in the logs: ActionCo...