ruby-on-rails

How do I test a ruby Mixin Module?

I'd like to know the best way to approach testing ruby mixin modules, in this case for use with ActiveRecord models, but really this is a general quesiton that applies to any class that you are extending with a mixin. Is it better to attempt to stub all of the necessary functionality of the Class that your mixin is extending, or just te...

Rails migrate date to string?

Hi Everyone, I have a field in my db table which is a date rather than string, how do I make a migration to convert it to a string? class CreateKases < ActiveRecord::Migration def self.up create_table :kases do |t| t.date :dateclosed Is it even possible? Thanks, Danny ...

Installing paperclip plugin

I'm trying to install the paperclip plugin with the following command: ruby script/plugin install git://github.com/thoughtbot/paperclip.git But I'm getting some errors: ruby script/plugin install git://github.com/thoughtbot/paperclip.git --force svn: '/home/app/vendor/plugins' is not a working copy /usr/lib/ruby/1.8/open-uri.rb:32:in...

Wrapping <%= f.check_box %> inside <label>

I have a list of checkboxes on a form. Due to the way the CSS is structured, the label element is styled directly. This requires me to nest the checkbox inside of the tag. This works in raw HTML, if you click on the label text, the state of the checkbox changes. It doesn't work with the rails <%= f.check_box %> helper, however, beca...

Can Rails unit tests be run on a different environment than test?

Hi, We have a large multi-developer project under Rails in which we are using tests for both models and controllers. Right now the developers have to switch the DB parameters for the 'test' environment to match their local dev environments before running tests. I am wondering if there is a way to run those tests on any environment other...

Why is Model.scoped generating invalid SQL?

When I run Book.scoped({:conditions => ['books.index LIKE ?','%query%']}) I get: ActiveRecord::StatementInvalid: SQLite3::SQLException: near "index": syntax error: SELECT * FROM "books" WHERE (books.index like '%query%') What am I doing wrong? ...

When using truncate I get the following error "index 113257 out of string"

What does this error mean? Here is the line of code that generates it apts[ndex] = truncate(results[ndex][:public_note].to_s,:length => 300) results is an array of activerecord objects ...

How do I write a spec to verify the rendering of partials?

I'm using rr (the mocking framework) and rspec with ruby-on-rails. Also, I'm using the collection short hand for partial rendering. My question: How do I correctly fill out the the following view spec? describe 'my_view' do before(:each) do assigns[:models] = Array.new(10, stub(Model)) end it "should render the 'listing' part...

Ruby on Rails: Uploading a modifed site.

I'm having a heck of a time getting a site I modified to work correctly. I didn't set the site up originally, and since the person that set it up no longer works with me I had to learn ruby just to make some changes. I made all the changes in the development server and everything worked fine. Then I did a diff on the production and d...

django/ruby on rails is community or enterprise based

i wonder if django has a community or an enterprise behind it for devlopement? the same with rails. thanks! ...

Finding out which higher level function is making lots of low level calls

Hi folks, I have a function that is being called more than a thousand times, slowing everything down. However, it is a low level function, and do not know which of my high level function is lopping and making these calls. How can i find out? ...

parsed xml file: skip creation if blank?

This could be a HappyMapper specific question, but I don't think so. In my app, users can upload their blog subscriptions (via an OPML file), which I parse and add to their profile. The only problem is during the parsing, or more specifically the creation of each subscription, I can't figure out how to skip over entries that are just ...

Relation/Sort not working in rails controller?

I have the following relation in my rails app: genre - has many - authors authors - belong to genre and has many books books - belongs to authors and belongs to users (users can add books to the db) in my controller I have: @books=current_user.books(:include => [:author => :genre], :order => 'created_at DESC') While I am able to...

How Do I Prevent Rails From Treating Edit Fields_For Differently From New Fields_For

I am using rails3 beta3 and couchdb via couchrest. I am not using active record. I want to add multiple "Sections" to a "Guide" and add and remove sections dynamically via a little javascript. I have looked at all the screencasts by Ryan Bates and they have helped immensely. The only difference is that I want to save all the section...

How can I add a property to child association before render?

Hi, I have a teacher model which has_many students. When I render a student (as json) I want to strip out the teacher_id property and replace it with the name of the teacher in my representation. What is the best way to achieve this? Cheers, Chris ...

Need a push in the right direction, to write my first functional test in Rails

I've read quiet a bit of documentation over the last few days about testing in Rails, I'm sitting down to write my first real test and not 100% sure how to tie what I have learned together to achieve the following functional test (testing a controller) I need to send a GET request to a URL and pass 3 parameters (simple web-service), if...

Front-end design first, or back-end development first? For Ruby on Rails site

I am doing everything on my own: front-end and back-end. I am proficient with HTML and CSS, but a noob in Ruby on Rails. Now that I want to develop the site, I wonder if I should start from front-end first, or back-end. Cos what I am doing for front-end now are all static. I am afraid that I have to change a lot of my front-end coding wh...

Rails: Duplicate functionality across controllers? A humble plea.

So I'm working with authlogic, and I'm trying to duplicate the login functionality to the welcome page, so that you can log in by restful url or by just going to the main page. No, I don't know if we'll keep that feature, but I want to test it out anyway. Here's the error message: RuntimeError in Welcome#index Called id for nil, which w...

Using a join model to relate a model to itself

I have two models: User MentoringRelationship MentoringRelationship is a join model that has a mentor_id column and a mentee_id column (both of these reference user_ids from the users table). How can I specify a relation called 'mentees' on the User class that will return all of the users mentored by this user, using the MentoringRe...

How do you share pre-calculated data between calls to a Rails web service?

I have a Rails app that allows users to build up a network structure and then ask questions about how to navigate around it. When adding nodes and connections these are just saved to the database. At the point you make a query of the network I calculate the shortest path from any node to any other node. Constructing this in memory tak...