ruby-on-rails

Posting a large body crashes our stack -- but only in production mode?

Our Rails application has two environments that we deploy to servers a Staging environment and the default Production environment. The staging.rb file is a copy of the production.rb form the config/environments folder. The difference between the two is whiny nils is set to true: config.whiny_nils = true Since the rails application ...

How to deal with .1 & .10 with MySQL & Rails

I currently have a MySQL database with a table that has a field that is typed as a decimal. Currently there are values that range from *.1 through *.9 but we now need to be able to handle the following: I need to be able to add *.10 to this field and sort it accordingly. In this use-case .10 DOES NOT equal .1! I need to be able to us...

Sorting model objects in the View - call Model method in View or implement sort in Controller?

By default when I call this: <table> <% @question.answers.each do |answer| %> <tr> The answers for a question are displayed in the order they were created. What's the appropriate way to sort them according to their votes? I'm not sure whether I need to call a method on the answers in the View or implement a sort function in the...

Testing for membership in a collection

If I know the current_user's answers because the User model has an answers collection: current_user.answers How do I test whether that answers collection contains the current answer (referenced by the @answer class variable) at each step of a loop? I was tempted to use the include? method: current_user.answers.include?(@answer) bu...

How to encode media in base64 given URL in Ruby

I'm trying to upload an image to PingFM. Their documentation says: media – base64 encoded media data. I can access this image via the URL. I tried (practically guessed) this: ActiveSupport::Base64.encode64(open("http://image.com/img.jpg")) But I get this error: TypeError: can't convert Tempfile into String from /usr/lib/ruby/...

Calling base class method from overloaded method in sub-class

Perhaps I am just not using the correct terminology for Ruby (and if I am please correct me), but Google just isn't helping me on this one. What I have is a class (call it OrderController) that extends another class (call it BaseStoreController). In the BaseStoreController I have defined a before_filter that is used throughout my site, ...

Rails unit testing doesn't load fixtures

Hello together, rake test:units fails in my current application, because the needed data of the fixtures is missing. If I'm loading the fixtures manually via rake db:fixtures:load RAILS_ENV=test the unit tests are working, but rake purges the test database. My test_helper includes fixtures :all and my tests are inheriting from it - bu...

Using gsub to replace a particular character with a newline (Ruby, Rails console)

Hey there Annoying problem. I am trying to replace all semicolon characters in my Model's description field with newline characters (\n). The database is sqlite. The field is of type text. If I do it manually at the rails console (manually typing the description for a single record using \n for line breaks), the rails console automati...

Rails - link_to, routes and nested resources

As my understanding on nested resources, on edge Rails, should not link_to 'User posts', @user.posts point to /users/:id/posts ? The routes.rb file contains map.resources :users, :has_many => :posts If this is not the default behavior, can it be accomplished doing something else? ...

Rendering another controller's view while keeping state

I have a blog model with has many model comments relationship. So my form looks something like this located in the blog show view: <% form_for [@blog, @comment] do |f| -%> <%= f.error_messages %> <%= f.label :message, "Add your message" %> <%= f.text_area :message %> <%= f.submit "Submit" %> <% end -%> All very straightforw...

the form reappears as if I had not submitted anything

I have the Shovell source code from Simply Rails 2 and it used to work, but now that I uninstalled everything, tried to program desktop apps for a while and reinstalled everything, it doesn't work. I go to shovell:3000/session/new, then submit anything, then shovell:3000/session without new in the URL is loaded as if I hadn't submitted ...

Where in Rails should I modify a base class?

I want to change Fixnum to include the a "weekend_days" method: class Fixnum def weekend_days //get correct days end end I want this available in my controllers and models? Obviously, I also need it to work in my tests. Where is the "rails" appropriate place to put this? ...

How do I have a negative scenario with Cucumber in Rails?

I have a negative scenario to test with Cucumber. Specifically, I want to make sure that when someone posts a URL with an invalid handle then the site returns an error. My scenario looks like: Scenario: create person with too short a handle When person named "Fred" with handle "tooshort" updates Then I should get a 500 ...

ActiveRecord counter_cache giving stale count with multi_db gem

I'm using the multi-db gem with Slony-I replication on PostgreSQL in a Rails app. This mostly works perfectly, but there is a bit of a replication lag in certain cases. One of the cases involves an ActiveRecord counter_cache. For clarity, assume the following two models: class Post < ActiveRecord::Base has_many :comments ... end c...

Frameworks that support complex nested forms ala Rails' accepts_nested_attributes_for?

I'm working on a small side project for a friend and I need to build complex forms dynamically from a set of predefined types which in-turn are persisted via the underlying object model. So far I'm using Rails 2.3.4, accepts_nested_attributes_for, and a bit of Javascript. There's nothing wrong with this, I've just about got it modified...

Rails named routes using complex parameter names

I need to create a pretty route for an action that is expecting ugly nested parameter names (this is set and not something I can change at this time). So instead of http://domain.com/programs/search?program[type]=leader&amp;program[leader_id]=12345 I want http://domain.com/programs/search/leader/12345 The problem is that Rails rou...

Rails: Pass parameters with render :action ??

I have a form that displays differently depending on the parameter it was called with. Ex. testsite.local/users/new?type=client So if type was a or b, the form would display different fields. My problem is when the form is filled out incorrectly, because if the user couldn't be saved corrently, it renders the form with the default e...

HAML & RoR: Auto-convert apostrophes, etc., to ASCII HTML entities?

Is there anyway to have HAML automatically convert all my apostrophe's ' to the HTML character entity equivalents (&rsquo;)? Ditto with all the other characters that one would want to convert (dashes, double-quotes, etc.) for better online readability. ? ...

SQLite and Ruby on Rails on PC

I am using instant rails which makes use of SQLite and I am unable to connect to the database. I have been using a tutorial that uses MySQL and I have been unable to find instructions for SQLite. Any suggestions? ...

OpenID with Authlogic openid-selector and yahoo

I've got registering/logging in working with at least Google and myOpenID with I thought should represent the two methods of passing parameters back from the provider but I'm not able to get an email or nickname back from Yahoo. I get passed to Yahoo's verification page but when I allow params aren't getting passed to my site. Here's my...