ruby-on-rails

How do I avoid nesting forms when offering inline editing of lists with checkboxes for mass updates.

A lot of sites offer the ability to edit lists of items inline as well as allowing multiple items to be selected via checkboxes and have an action performed all at once e.g. delete, mark as spam etc. But how do you implement this without violating html rules. I need one form for the checkboxes with individual submit_tags for the mass ac...

How to install a plugin from github?

I have tryed to run this code in my console: script/plugin install git://github.com/apotonick/cells.git ...but i only get an empty folder named "cells" in my "vendor/plugins" dir. What's wrong? ...

Advanced find in Rails

Hi all I really suck at Rails' finders besides the most obvious. I always resort to SQL when things get more advanced than Model.find(:all, :conditions => ['field>? and field<? and id in (select id from table)', 1,2]) I have this method: def self.get_first_validation_answer(id) a=find_by_sql(" select answers.*, answers_registrati...

Ajax post request, an object that includes an array and other objects, can't be parsed correctly into rails, if i do it with jQuery it works but i dont want jquery im doing it in native javascript.

what i want is to get a proper parameter, if you see the parameter been logged you would tell there is something wrong my javasript: first run the runMe function Ajax: function() { var xmlhttp, bComplete = false; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHT...

Rails: generate .js file at runtime

Hello, I've a .js file in my public/javascript folder, I want to include a dynamicaly generated value in this file. Is it possible to have a .js file dynamicaly generated, something like public/javascript/my_javascript.js.erb Thanks ...

How do I Order on common attribute of two models in the DB?

If i have two tables Books, CDs with corresponding models. I want to display to the user a list of books and CDs. I also want to be able to sort this list on common attributes (release date, genre, price, etc.). I also have basic filtering on the common attributes. The list will be large so I will be using pagination in manage the load...

Start or ensure that Delayed Job runs when an application/server restarts.

Hi there, We have to use delayed_job (or some other background-job processor) to run jobs in the background, but we're not allowed to change the boot scripts/boot-levels on the server. This means that the daemon is not guaranteed to remain available if the provider restarts the server (since the daemon would have been started by a capis...

Why are my rails tests so slow?

Is it normal for my test suite to take 5 seconds just to launch? Even when running an empty suite it still takes this long. Is it because it's firing up a new instance of rails on each run? If so, is there anyway to keep it persistent? Example: rlepidi@rlepidi:~/projects/rails/my_project$ time rake test /usr/bin/ruby1.9.1 -I"lib:test" ...

Exclude some ids from result in Rails ActiveRecord

I have following statement for query articles from some sections Article.all(:joins => :sections, :conditions => { :sections =>{ :id => [3, 4, 6, 7, 8, 9] }, :id_not_in => @some_ids }, :limit => 4) Variable @some_ids is array with ids of articles wich must be excluded from result. ...

Overriding content_type for Rails Paperclip plugin

I think I have a bit of a chicken and egg problem. I would like to set the content_type of a file uploaded via Paperclip. The problem is that the default content_type is only based on extension, but I'd like to base it on another module. I seem to be able to set the content_type with the before_post_process class Upload < ActiveRecor...

Many passenger config on same domain for many rails apps ?

Hello, I would like to have individuals config for my rails apps on my server, using passenger. How to do it ? For example, I want to have different PassengerPoolIdleTime ... ...

Strange rails behaviour: class methods doesnt work as expected...

In Profile model class def add_friendship_request(friend_id) Friendship.testing2 # doesnt works Profile.testing2 # works end def self.testing2 'ss' end in my Friendship model class def self.testing2 'ss' end I got this error: undefined method `testing2' for #<Class:0x58eea7c> Fixed: restarted my pc ...

Cleanup ActiveRecord field

I have model Article it has field title with some text that may contain some "magic" patterns. In some cases i need to process text in title and other cases i don't, but in last case i need to get string w/o that patterns. For example i have title value like "Something **very** interesting" and when i call @article.title i need to get c...

What is the meaning of "-" in blocks of server-side code in ruby on rails?

I often see things like this in rails views: <% form_tag some_path do -%> <% end -%> Why is there a "-" at the end of each of those lines? My code works fine without it, but is it a best practice or some kind of security measure? ...

Authlogic with nested attributes and polymorphic associations

Hi all! I'm having trouble with the following code: User < AR acts_as_authentic belongs_to :owner, :polymorphic => true end Worker < AR has_one :user, :as => :owner accepts_nested_attributes_for :user end Employer < AR has_one :user, :as => :owner accepts_nested_attributes_for :user end I'd like to create registration ...

RMagic Error in rails, with AM Charts

Hi Everyone, I'm using AMCharts and rails. AMCharts uses the Image Magic lib to export an image of the chart. In rails this is done with the gem, RMagic. In a controller this is implemented with the following controller method: def export width = params[:width].to_i height = params[:height].to_i data = {} img = Magic...

Is it OK to manage associations manually?

Here are the relevant models: User Product Order A User can sell or buy products An order has a buyer, a seller and one product I know that I can do this with a HABTM relationship between orders and user, but is seems to me like it would be simpler to put in the Order table the following columns: :seller_id :buyer_id and manage thos...

Are there any Rails Plugins that use JS to poll the server for completion of a background process?

I know it might be simple to write some polling JS that asks the Rails application if it has completed a background job. But I wonder if anyone has already packaged up this functionality as a plugin. Basically, I have a few delayed_jobs running, and am looking for a plugin that will poll the server for completion of a particular job, th...

Setting Rails Checkbox from Another Model

I have a checkbox that belongs to "Foo" class. I have another "Preferences" class that sets the default for what that checkbox should be. I tried using f.check_box :email_preference, :value => preferences.email_preference but it doesn't work. I use this page to do new record creation as well as edit, so obviously for new records I ...

How do I get the "Install Missing Plugin" yellow bar to appear in firefox when flash is not installed?

My rails website uses the open_flash_graph plugin to generate flash graphs for my clients. If a customer doesn't have flash installed, it doesn't display any messages, it simply doesn't show any graphs. I've noticed that if I go to other websites that need flash, I get a yellow bar at the top of my firefox window that offers to "Instal...