ruby-on-rails

How to produce several forms for a nested form ?

Intro I have an object @organization that has_many :quick_facts Basically, I want to produce a _form for each :quick_fact but with one save button, that saves all of the quick_facts. My two problems: First Problem: My quick_facts are not prepopulated with their information. They only appear as blank for each quick_fact I have. Se...

self.update_attributes not updating the attribute

I'm calling update_attributes but it doesn't seem to be changing the object. def add_to_vote_count(increment) vc = vote_count ? vote_count : 0 puts "CALLED a_t_v_c(#{increment}), NEW VOTE COUNT SHOULD BE #{vc + increment}" self.update_attributes(:vote_count => (vc + increment)) end Here's some console testing: ruby-1....

Lots of fields in a model, but want to have a public / private attribute for all of them.

I have a model where almost every field needs to have a public / private flag (boolean) for each item. At first I thought I'd make a boolean for each field, however, I am not sure if thats the best way of handeling this. Is there a better way? I'm up for all suggestions. ...

How to make a function call that happens only once in Ruby/Rails

A gem/plugin that I'm using to support my test suite calls some GNU commands that cause the Windows shell to roll over and die. I can rewrite these functions with a bypass in this fashion: def get_rake_output(task) if RUBY_PLATFORM.include? 'mingw' puts 'Skipped since OS is Windows. Run the test suite on a UNIX-like shell.' ''...

values are lot loaded from the form during validation

I have ruby user model which has its validations written in separate file called validations.rb. This user model has an associated tasks model which has separate validations for it. During validation of user.rb, the code in validations.rb is trying to get the tasks that were entered in the form but it fails and instead gets the existing ...

How to change file permission of all files in a S3 bucket using either aws-s3 gem or right_aws gem

Is there a way to change the permission of every single file in a S3 bucket using either aws-s3 gem or right_aws gem? I can't find it in the documentation. Do I have to do each file individually? I would like to grant "everyone" view permission. ...

Rails3 and Arel to select using IN and subselect

I have a table called translations. (And a correspoding ActiveRecord class). This table contains the following fields id, key and value I would like to select all translations where the key matches a given query + all the translations that don't match the query, but share the key with a translation which does matches the query. The res...

rails form options helpers: is using a non-integer :selected value possible? (preselect)

i am trying to get a rails select form options helper to get a :selected value that is non-integer. actually i am using the object-id format from mongodb. the html example: <option value="4c613e3c8ee60a1c31000024">test</option> rails select: <%= select( "question", "#{number}", active_question.answers.collect{|x|[x.title, x.id] },{:...

Rails 1.x client talking to RESTful server

Hey all, I've got a client that is integrating a Rails 1.2.6 site with another site that exposes services RESTfully. Upgrading to Rails 2.x is not an option at this time. Does anyone have recommendations for methods other than direct Net::HTTP calls to communicate with the REST service? Techniques or Gem recommendations are welcome, b...

Ruby 1.8.7 vs Ruby enterprise

From what I understand REE is better in terms of garbage collection and much faster when combined with Passenger. Are there any downfalls of using REE as opposed to Ruby 1.8.7? Random bugs on REE? Compatibility errors? Not advisable for beginners? This is the only result I found: http://stackoverflow.com/questions/1402010/ruby-enterpri...

Dynamically adding items to a select list in Ruby On Rails using Ajax

I have looked at a whole bunch of solutions for this and maybe I am just dense, but I can't get anything to work. These are the two selects I am trying to tie together in a product/new view that will allow the user to select a category of product and then constrain the subcategory listing: <p> <%= f.label :category_id %>: <%= f...

How do I test a rights-managed Rails application?

I'm working on a Rails application that requires you to be logged in to see pretty much anything. For unit tests, this isn't a problem since they interact with the model directly. For integration tests, this isn't a big problem since I can just have the appropriate user log in via Rails' post method. It seems like it makes sense to put a...

Forum name not displaying...

Not sure why. My model defines the object forum def index @forum = Forum.find(params[:forum_id]) But in my view it won't display the forum name. This code just comes up with "Forum : " <h2>Forum : <%- @forum.name -%></h2> The forum database table exists, and has an object that should be displayed! mysql> desc forums; +----...

Easy Ruby data table/search question

Hello, So I have a table that looks like this: A B A C B A C A C B I want to delete the lines that the connection of two values are already in represented (so A----B is the equivalent connection as B----A). Basically I want my table to look like this. A B A C B C How can I do this in Ruby? -Bobby EDIT: H...

Ordering objects by a sum of has_many association

I have two objects: class Person < ActiveRecord::Base has_many :tests end class Test <ActiveRecord::Base belongs_to :person end I need to sort all my person objects by the sum of scores on the test. One other trick is each person may not have a test. I've gotten as far as this with my tests but I can't get them to order based ...

Geokit and rails 3

Hi, I am using the geokit gem and plugin with rails 3. It seems there is a known issue with them, which can be seen here http://github.com/andre/geokit-rails/issues#issue/15 Now, I tried to follow the solution provided at the bottom. I pasted that function definition, at the end of the file, just above acts_as_mapable, and just after t...

How can I limit the amount of words displayed from a Ruby string?

Hi there, the Ruby code is below: <%= product.advert_text -%> What script should I add then can limit the words amount? Many thanks for anyone's advice. ...

Facebooker with authlogic, problem with script/generate xd_receiver

Hi, I'm trying to follow the tutorial at http://github.com/kalasjocke/authlogic_facebook_connect#readme and getting stuck at the $ script/generate xd_receiver line. It gives an error: Couldn't find 'xd_receiver' generator I read up on similar issues, which said to install the typhoeus gem. I did that and I also made sure that my fac...

Validate words against an English dictionary in Rails?

Hi there, I've done some Google searching but couldn't find what I was looking for. I'm developing a scrabble-type word game in rails, and was wondering if there was a simple way to validate what the player inputs in the game is actually a word. They'd be typing the word out. Is validation against some sort of English language diction...

RJS error in Ruby on Rails

Why does this: <%= update_page_tag do |page| page["femenino"].hide end %> Generates this? <script type="text/javascript"> //<![CDATA[ try { $("femenino").hide(); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('$(\"femenino\").hide();'); throw e } //]]> </script> I have the DIV with ID "femenino", the update_p...