ruby-on-rails

render partial using ujs and without AJAX call on rails 3

I need to do multiple file uploads using nested form and jQuery. so I wrote an helper using link_to_function method: def add_document_link(title, form) link_to_function title do |page| form.fields_for :documents, Document.new, :child_index => Time.now.to_i do |f| page << "$('#documents').append('#{escape_javascript(r...

How do I save tabular data in rails?

I'm writing and app to let the production people estimate costs for building some products, they want to be able to give the product's base data (name of the product, client, etc) plus make the recipe for it (which materials are needed in order to build it) in the same page, and I was wondering how do I save tabular data in my rails co...

Thinking_sphinx sorting through associations

I am trying to sort the search results of a thinking_sphinx search. The columns I want to sort are in associated tables: class Membership < ActiveRecord::Base define_index do indexes :title indexes user.first_name, :as => :first_name indexes user.last_name, :as => :last_name has :organization_id, :active set_property...

Is it possible to make a relationship between an ActiveRecord model and a plugin's model?

I'm using ruby on rails 2.3.8, and I've installed the acts_as_taggable_on plugin for tagging announcements and everything was fine until I discovered I had no easy and neat way of getting all the announcements tagged with a certain id(the only method I found was Tag.tagged_with(tag_name)). So, I just wanted to relate the Tag model of th...

rails custom validation :on => :create not working

I have a "custom" validation method that I only want executed on create like: validate :post_count, :on => :create def post_count # validate stuff end but it gets fired on update (in addition to on create). Does the :on => :create symbol not work with "custom" validation methods? THanks! ...

What would cause this migration to hang?

I'm trying to upgrade an old 1.2.6 Rails application to 2.3.8, and I'm running into a bit of a snag with migrations. Namely, if I have something like ModelName.create(:foo => "bar") in the migration, the migration doesn't complete. It doesn't hit an infinite loop or anything. It just refuses to complete that migration. Here's some sampl...

In Ruby on Rails, when in the View, can you dump out the files and line numbers before reaching View?

The first layer is routing and the second layer the controller, so when in View, is there a way to dump out the path or filenames and line numbers of route and controller before reaching view? I wanted to do this because www.example.com/stories/12345 is showing a page, but stories_controller.rb doesn't have a def index or def show Upda...

Can't sudo gem uninstall (you don't have write permissions)

I'm having trouble removing a gem from my system. When i ask gem where RedCloth is installed it says this: pteng01:trunk mike$ gem list -d RedCloth *** LOCAL GEMS *** RedCloth (3.0.4) Author: why the lucky stiff Rubyforge: http://rubyforge.org/projects/redcloth Homepage: http://www.whytheluckystiff....

How do I stop the phusion passenger spawn server from restarting?

I have Phusion Passenger running my Ruby on Rails application on my local machine, but I'd like to be able to kill the process entirely and run a different (non-Apache) service on the same port. Unfortunately, when I kill the passenger spawn server and the httpd processes, the spawn-server restarts: 15:30:37 /usr/bin $ ps ax | grep pas...

Where does one find Rails deprecation warnings?

How can I know that I'm seeing all deprecation warnings? Will they all print out at boot time? So firing up the console and viewing the output should be sufficient? (if so, I don't have any. w00t!) Thanks, John ...

What does cPanel actually do to create a Rails app?

I am wondering what actually happens behind the scenes on the server when I create a Ruby on Rails application through the cPanel interface. Is it just calling $ruby script\generate $ruby script\server Or is there more to it? ...

Why would my rake tasks running via cron get invoked twice?

I have a rails app with the whenever gem installed to setup cron jobs which invoke various rake tasks. For reasons unbeknownst to me, each rake task gets invoked twice at precisely the same time. So my db backup task backs up the db twice at 4:00am. Inspecting crontab reveals correct syntax for all of the cron jobs, so I don't think th...

Can a Rails app launch a rack app?

If I have a Ruby on Rails application running on my Apache shared server (with Mongrel), can I get it to launch/run another total separate Rack application? Then could I possibly build a Rails app that manages other rails/rack apps? So it could tell what apps are running and start/stop them when I want. Or is each app trapped in it's ow...

What's the best way to use yajl-ruby with my Rails project?

Rails 2.3.6 started using the fast new json library, yajl-ruby, "if available". In the "JSON gem Compatibility API" section of the yajl-ruby readme it outlines a method to just drop in yajl-ruby inclusion and have the rest of the app seamlessly pick it up. So, ideally, I'd like Rails to use it My gems to use it My application code to...

How do I nest a div inside an anchor tag in rails.

I'm a bit of a Ruby on Rails amateur, and I am trying to nest a div tag inside of an anchor tag in rails. I can make it work, but the resulting code I have written is terrible and is certainly NOT the rails way. Here is an example of what I am trying to accomplish in HTML: <a href="tell-a-friend"> <div id="tellafriend"> <strong>Str...

Mechanical Turk: Post file to externalSubmit interface?

I have setup my own custom form for mechanical turk and am posting to their external interface. <form enctype="multipart/form-data" action="https://workersandbox.mturk.com/mturk/externalSubmit" method="post" name="mturk_form" id="mturk_form"> <p> <label for="turk_task_image_image">Upload an image</label><br> ...

Delivery issues with Rails + Gmail SMTP in Dreamhost

Hi! I just released a Rails app in Dreamhost and I'm using Google Apps for my domain to handle Emai. I created the [email protected] account to serve as the sender authentication. I installed smtp-tls plugin and my smtp conf is: config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :enable_starttls_auto =...

order by association

Here are my models. Restaurant has many patrons patrons have many transactions In controller index all patrons like @pts = Restaurant.find(1).patrons and in view I simply list the patrons attributes, inluding number of transaction per patrons like <% @pts.each do |p| <%= p.transactions.count %> How would I order the resultset (@pts...

Rails: Rendering a partial to the right div?

I have a loop in my view that renders many partials: each partial is a simple toggle to perform a save/unsave operation on a record. Each partial toggles the boolean field using javascript then updates itself, and the controller finishes by saying: $ controller render :partial => "save_unsave_buttons", :locals => {:matching => @matching...

How do you order an array by a connected integer in Ruby on Rails?

I'm creating a most popular activity section for user profiles. I have no difficulty pulling questions through the user_id but I'm having trouble pulling then ordering by the associated integer: question.votes.size . This is probably a simply question but how do I sort then limit the output to 3? How do I do this without lagging the data...