ruby-on-rails

Rails 3 - How to Not to Error if no record is found

In my permissions controller, I use Active record to look for a permission: @permission = Permission.find(params[:user_id]) If this returns a result I then look up the permission.name And pass this to my controller. Problem is sometimes this does returna result, othertimes it does not. When it does not, it errors. How can I prevent t...

Seeding file uploads with CarrierWave, Rails 3.

I'm trying to seed a database in Rails 3 with images using CarrierWave, however nothing I try seems to work short of having to upload them all by hand. pi = ProductImage.new(:product => product) pi.image = File.open(File.join(Rails.root, 'test.jpg')) pi.store_image! # tried with and without this product.product_images << pi product.save...

What is the best language for fast web development?

I have an idea for a simple web application and I've heard a lot about Ruby, Ruby on Rails, Python, PHP, etc. But what language do you think is better to have working prototypes and get the application running online really quick? NOTE: This is not a question about the language's performance, I am just trying to find the best language...

undefined method `update_attribute' for ActiveRecord::Relation when called on record retrieved through inheritance

I have a polymorphic association relationship happening, and when I retrieve a record through it, such as: hour = my_model.find( keeper_id ).hours.where( "day = ?", day_index ) Then try to call update_attributes on it: hour.update_attribute(:start_time, start_time) I get an error: NoMethodError (undefined method `update_attribute'...

Sunspot Solr matching a single object

I use the Sunspot gem in my RoR app to do searches on the Post model, and it works great for that. However, I need to use it's matching algorithm against a single post object. For example, I can search all Posts like this: Sunspot.search Post do ... end But, I need to do the search against a single post object, like so: Sunspot.se...

Getting [email protected] when trying to display eamil using collection_select

I am using Ruby 1.8.7 with Rails 2.3.9. When creating a drop down of email addresses using collection select, the emails addresses are not displaying. Instead I am seeing "[email protected]" in the drop down. Is there some switch that is causing this? There seems to be some javascript that is being applied to each item in the drop d...

Form_for a Nested Resources Permissions (Y Model)

Hello, could really use your help, understanding this complex rails issue I've been banging by head against the wall on... I have the following Models: Permissions (user_id, role_id, project_id) Roles (id, name) Projects (id, name) Permissions is the Y model for Roles and Projects. I'm struggling to make a form to allow a user t...

When using HAML, is there a way to use heredoc or %Q{ ... } ?

Maybe it can be put into a helper but the existing 500 lines of code has everything in the HAML code, so it is better to follow the existing code for the moment (for tight deadlines). I found the only way working right now is - meta_tag = %Q{\n | <meta ...>\n | <meta ...>\n | [...] \n | } | which is to use the "continuati...

Ruby on Rails - Locomotive for version 2.3.8 -- is there such a thing?

I am looking for a piece of software that will allow me to use Ruby on Rails 2.3.8 on top of MACOSX - basically, I teach at a college where students are not able to get terminal acccess to the rails built into OSX so I am looking for a piece of software like "Locomotive" that is an app that allows students to use rails without administra...

Restful Rails Edit vs Update

I was trying to redirect to a different page after editing an entry, I assumed that it was using the update code because you are updating the database. It took me some time to realise that I was using the wrong action in the controller. Can someone please explain how edit and update work. Why are there two different actions? what are t...

Ruby on Rails Routing issue

I'm getting a Routing error when trying to access my page. Routing Error No route matches "/" with {:method=>:get} The error log reads: [4;36;1mSQL (0.1ms)[0m [0;1mSET NAMES 'utf8'[0m [4;35;1mSQL (0.0ms)[0m [0mSET SQL_AUTO_IS_NULL=0[0m Processing ApplicationController#index (for 68.116.193.166 at 2010-10-11 19:18:16) [GET] ...

Nested form in rails 2.3 which updates one model but creates the other

So I have 2 models, listings, and houses. Houses can be made independently, while all listings must be associated with a house (this a an apartment-finding site). I am trying to build a form for a new listing which has a column alongside of houses already in the database. If the user sees their house, they click it, and the form auto-fil...

Mongo Design question with Rails/Mongoid for a bill tracking app

I'm writing a quick app for a user to track their daily bills (for money tracking purposes). I want the user to be able to define their own categories that a bill can be applicable for. I'm trying however to decide the best way to model this and also validate categories as unique. My initial thought was this: class User include Mon...

Behavior Driven Development using existing software components

I'm currently reading through the beta version of The Rspec Book: http://www.pragprog.com/titles/achbd/the-rspec-book It describes The Behaviour Driven Development Cycle (red, green, refactor) as taking small steps during the development process. This means adding features one at a time. My question is: If I were to describe a single...

Is there an exit in ruby?

I use php and there is a handy exit; that will stop the execution of the page and let me view the page thus far and then lets me view the debugging that i need ..anything like that in ruby on rails ...

Newbie rails question: elegant way to deal with nil values in .each loops?

Hi folks, Just meddling with Rails at the moment, and struggling to figure out how to escape "you have a nil object when you didn't expect it" errors . At the moment I'm escaping each of them with an "unless object.nil?" message, but it's getting pretty ugly. Case in point: unless params[:professiontypeinfo].nil? unless params[:profe...

Checking HTTP result code of a HTTP request, if the URL isn't valid the app crashes. How can I catch the error instead?

I'm using Restclient (HTTP and REST client for Ruby) to check if a URL is valid. The Restclient response wraps Ruby's Net::HTTPResponse. p (RestClient.get "www.google.com").code == 200 # outputs true The problem is, if the URL isn't valid, the app crashes: p (RestClient.get "test").code == 200 SocketError (getaddrinfo: nodename no...

rails update redirecting to wrong controller

I have a model for a task which has a name, description, the process it belongs to, the position and a category. As there are only two different categories I have created additional controllers specific to the categories as they need to be treated differently. when i submit the edit form in one of the category controllers it is redirect...

Overriding show/edit/etc behaviour in ActiveScaffold

I currently have a generic list that is generated by ActiveScaffold. At the end of each row in the list, ActiveScaffold adds the standard CRUD links - Show, Edit, Delete - for each record. I do not wish to use ActiveScaffold for these actions (long story) and have created my own controllers to handle this. I am trying to override these ...

Used Background for some Scenario

Feature: list video in stored Background: Given I have the following videos | title | format | | Running Central Park in the Fall | BluRay | | Running Glacier Park in the Spring | Download | | Running Balboa Park in the Winter | DVD | ...