ruby-on-rails

What's the cleanest way to add a class attribute to an html element in a view in rails

I'm writing some Rails code for a partial view, and I want it to only show a comment field if somebody is already logged onto a site here. If the page is viewed by someone who isn't a member of the site yet, the shared/comment_not_logged_in fragment should be passed in. However, I'm totally stumped as to why I can't run the same check ...

Good Ruby on Rails Free Hosting

Hello, What is the best place to go for free Ruby on Rails web hosting? I'm starting my project and I don't need a really good package for hosting, but if my project begins to grow then I'll pay for the best! Thanks. ...

How can I see what actually happens when a Test::Unit test runs?

In a Rails application I have a Test::Unit functional test that's failing, but the output on the console isn't telling me much. How can I view the request, the response, the flash, the session, the variables set, and so on? Is there something like... rake test specific_test_file --verbose ...

How should I handle model attribute that doesn't match request params?

I have a model like this... Receipt ------- amount:int # => An amount of money stored as cents. But in the view I have these fields... amount_dollars amount_cents So mass assignment won't work there. What is the standard way to deal with this situation? Where do you put the code that converts the incoming values into an amount of...

Setting the scope on a model for the rest of a request

I'm wondering if there is a way to set a scope on a model class for the rest of a request? I.e. I want to scope down some results, but I want to do it without the main restful controller knowing (perhaps in a before_filter injected into the controller). Contacts.scope = { :conditions => {:public => true} } if ladeda then later on Con...

How to create "Upcoming birthdays" module in Rails?

Hi, I have a table "users" with a column "date_of_birth" (DATE format with day, month, year). In frontend I need to list 5 upcoming birthdays. Spent ages trying to work out the logic.. also browsed every possible article in Google with no luck.. Any suggestions how to do this in RoR? Thanks! ...

Keeping track of who did what in Rails?

What's the best practice way for keeping track of who did what in a mid-sized Rails app? Intercepting all database read/writes and storing that in another table? ...

How to read JSON from Ruby on Rails with ExtJS

I have some existing projects that were built upon a deprecated PHP framework, and I'm hoping to move them over to Ruby on Rails with minimal effort. My main problem right now is the format that the JSON is coming back in. My frontend code (all ExtJS) is expecting JSON in the format: { "result": [ [id: 1, name: "mike"], ...

Ruby on Rails vs. Django

Possible Duplicate: Rails or Django? (or something else?) These are two web frameworks that are becoming (or have been in many circles) popular. I was wondering what are the advantages and disadvantages of each? Feel free to comment on Ruby and Python pros and cons also. Two disadvantages I am speculative about for RoR is the s...

Rails :overwrite_params with nested parameters

Hi. I'm using the :overwrite_params option in link_to helper. But I have problems overwriting nested parameters values. Here some code: With: link_to book_item.editorial, :overwrite_params => {:filter => {[editorials.id] => book_item.editorial.id.to_s}} The complete params[:filter] value is replaced (ie. I lost params[:filter][:auth...

How to determine Controller class given URL string

Within the scope of a Rails controller or a view: How can I query the Rails routing mechanism to turn a relative url string (eg "/controllername/action/whatever" into the controller class that would be responsible for handling that request? I want to do something like this: controllerClass = someMethod("/controllername/action/whatever"...

What is the best payment gateway to use with ActiveMerchant?

I need to set up a payment solution within one of our Rails apps using the ActiveMerchant library. Although this question is highly subjective, what are people experiences with the major gateways out there (BrainTree, Authorize.net etc)? It must: handle recurring payments. have the ability to credit a persons account. have the ability...

Ruby - undefined method `fdiv' for 0:Fixnum

Over the weekend, for some reason, one of our servers has decided to start throwing the following errors (nothing has changed). Any ideas?: /!\ FAILSAFE /!\ 09:57:05 AM Mon, 29 Jun 2009 Status: 500 Internal Server Error undefined method `fdiv' for 0:Fixnum /usr/lib/ruby/1.8/yaml/rubytypes.rb:146:in `is_binary_data?' /usr/l...

Allow users to remove their account

I am developing a gallery which allows users to post photos, comments, vote and do many other tasks. Now I think that it is correct to allow users to unsubscribe and remove all their data if they want to. However it is difficult to allow such a thing because you run the risk to break your application (e.g. what should I do when a commen...

Hpricot Element intersection

Hi, I want to remove all images from a HTML page (actually tinymce user input) which do not meet certain criteria (class = "int" or class = "ext") and I'm struggeling with the correct approach. That's what I'm doing so far: hbody = Hpricot(input) @internal_images = hbody.search("//img[@class='int']") @external_images = hbody.search("//...

How to raise an ActiveRecord::Rollback exception and return a value together?

I have a model that uses a acts_as_nested_set fork, and I've added a method to the model to save the model and move the node into the set in one transaction. This method calls a validation method to make sure the move is valid, which returns true or false. If the validation fails, I want my save method to raise ActiveRecord::Rollback to ...

Where do you put CSS files in a rails app directory?

Where should i create a folder to house my CSS files within my rails app directory?? ...

How do I use a stored payment source for a purchase in ActiveMerchant?

I'm using ActiveMerchant with Braintree as my payment processor. I want to take advantage of Braintree's customer vault functionality to store credit card info. Storage goes fine, but I can't figure out the correct way to charge the credit card with the customer_vault_id. It seems very straight-forward according to the Braintree docume...

jquery pop up box, Pull from a database RoR

Alright. I'm working in Ruby on Rails and what I have is a table the is being pulled from a database like so. <% @businesses.each do |business|if !business.approved %> <tr> <td><div class="button<%=h business.name %>"><a href="#"><%=h business.name %></a></div></td> <td><%=h business.address %></td> <td><%=h busin...

how to RESTful-ize a complex controller

I have a controller with actions: class GameController < ApplicationController before_filter :set_titles def prestart end def wait end def play (game) end def button end def finish end def set_titles end set_titles will get the page title (and other general properties for all actions) All other actions check for something and ...