ruby-on-rails

observer does not work in IE

In my ruby on rails app I am trying to use a Prototype Form.Element.Observer to run a count of the characters in a message. This works fine on Firefox/Safari/Chrome, but not on IE. On IE the observer simply does not fire. Is there a fix or a different way of doing this? My ruby tag looks like this: <%= countdown_field('txtmsg[memo]'...

Proper syntax for boolean condition in find

I want to search through users whose show attribute is true. show = true @users = User.find(:all, :conditions => ["show = ?", show]) This doesn't appear to be working for me. ...

Use custom id for check_box_tag in Rails

How do you set a custom id when using a check_box_tag helper in rails? I have a loop which creates a bunch of checkboxes based on a collection: - subject.syllabus_references.each do |sr| = check_box_tag 'question[syllabus_reference]', sr.id, :id => sr.id = label_tag sr.id, sr.name I would like to set a custom id so that m...

using helpers properly in ruby on rails

It looks like you cannot use a helper in a controller even if both of them belong to the same class. For example: XYZHelper and XYZController... I was under the impression that if the prefix is the same "XYZ" then the method in the helper can be used in the controller and in the view, but I think this is not the case. So how do I remov...

Adding an icon to form button

I am using the following code to position an icon on top of a button: <a href="/users/hide_profile" class="button"> <span class="hide_profile">hide public profile</span> </a> a.button{ background-image: url('/images/button.gif'); display:inline-block; position: relative; _display: inline; color:#888888; font-w...

Rails FormTagHelper missing important select and collection_select methods

You can do this when you use form_for(@model...): collection_select(:subscription, :duration, ["Some", "Values"], :to_s, :to_s, {:prompt => true}) And the output is something like this: <select id="subscription_duration" name="subscription[duration]"> <option value="">Please select</option> <option value="Some">Some</option> ...

NoMethodError in Nutritions#new - undefined method '' for nil:NilClass

I have an error in my nifty_scaffold... For some reason (didn't change any standard code, checked the routes.rb, ...), creating a new nutrition won't work. Could anyone explain me how and what the solution is? I think i have included all necessairy code... The error in detail is: undefined method `generated_methods' for nil:NilClass ...

Simple Horizontal Javascript Navigation with Prototype

I'm trying to implement a simple horizontal navigation menu that just shows a single div for each link. It is kinda like a dropdown menu but instead of a mouseover triggering a dropdown, an onclick event will trigger the showing of a div. I want to make sure I am taking the right approach before going too much further, any help is appr...

Changing the `Proc` binding during invocation

Is it possible to change the binding of a procedure during invocation time? class AllValidator def age_validator Proc.new {|value| self.age > value } end end class Bar attr_accessor :age def doSomething validator = AllValidator.new.age_validator validator.call(25) # How to pass self as the binding? end end In th...

Getting rmagick to work with Phusion Passenger

I'm trying to deploy my app using Phusion Passenger on DreamHost and I'm very close ... I've unpacked my gems [ecco]$ rake gems (in /home/myuser/myurl.com/trunk) - [F] authlogic - [R] activesupport - [F] cancan - [F] formtastic - [R] activesupport >= 2.3.0 - [R] actionpack >= 2.3.0 - [F] paperclip - [F] rmagick - [F]...

ROR: Localised Message String Variable Substitution

I am trying to work out the best way to replace multiple variables/placeholders within localized message string in my ruby on rails application. When replacing a single placeholder I have used the satisfactory: In en.yml: url_borked: "The URL: $url could not be loaded." In view: t(:url_borked)["$url"] = request.url But this is ...

Elegant way to process collection_select in controller?

I am currently somewhat stuck figuring out an elegant solution to my following problem: Let's say I have the following classes: class Event < ActiveRecord::Base belongs_to :reg_template, :class_name => "EmailTemplate" [...] end class EmailTemplate < ActiveRecord::Base has_many :events [...] end And a view that contains: <%...

How to get instance_of to work with ActiveRecord objects in RoR?

Today I ran into an issue using RoR to stub calls to AR objects. I thought that I'd be able to do something along the lines of : stub.instance_of(BankAccount).save_to_other_spot { true } However when I tried this method it didn't seem to stub the method at all and it would end up running the original method I was trying to stub. I con...

Rails Photos, Users, Comments

Hi, It's driving me crazy. I have 3 models. User, Photo, Comments. Here is what I want to do. A user has many photos and comments A photo belongs to a user and has many comments And a comment belongs to user and to a photo So my models have these associations: User has_many :photos, :dependent => :destroy has_many :comments, :de...

Error while updating a record using Formtastic in HAML templates

I am using formatastic in a HAML form. - semantic_form_for @company do |f| - f.inputs do = f.input :description = f.input :type = f.input :industry = f.input :hq = f.input :products = f.input :subsidiaries = f.input :employees = f.input :revenue = f.input :net_income = f.buttons When ...

Drawing the line between the model and the Controller

I'm building this restful application using RoR, and am finding it a bit difficult to draw a line between things that should go on the model, and things that should go on the controller. As an example, I have 7 methods on my controller (the ones that make it restful i.e. index(), show(), create(), update()...), and often find that it's ...

Rails - Changing the parent of a child and ensuring callbacks are executed

If I have class Parent < ... has_many :children, :before_add => :prepare_baby_room :after_remove => :plan_holiday end class Child < ... belongs_to :parent :after_create => :gurgle_a_lot :after_remove => :cry end and I want to re-associate a child with a different parent, what's the cleanest way to do it whilst ensu...

Issues using a link_to_remote to change the state of the database?

hi, anyone know of any issues using a link_to_remote to change the state of the database? I'm taking about issues with spiders, google accelerator etc. Twitter seems to do it with no problem. Thanks ...

elastic css framework with rails 3 and haml/sass ?

hello fellow programmers, i recently stumbled upon "elastic css" framework, which looks like a good thing to me. i tried blueprint already but i must say this seems to be an overkill for me (tried it with compass). so my question to you rails/xhtml webdevelopers out there: is the elastic css framework together with rails (3) and haml/sa...

rails 404 422 500 completely blank

This is probably very simple but I can't figure out why I get no error pages. First off, I'm using Heroku for hosting, so it's definitely in production mode. If I set the line "config.action_controller.consider_all_requests_local" set to true, I get a detailed error message but otherwise, I get a completely 100% blank screen. If I vie...