ruby-on-rails

Is there any harm in using a typical GET action for a PUT? (RESTfully speaking)

I have an action that doesn't require a form. So it really only needs the one 'edit' method instead of the RESTful 'edit' --> 'update'. Is there any reason not to do this or a better way? def edit #Do a POST(PUT) end ...

How do you use multiple form fields to interact with a single method in rails?

I have a model which has start_at and end_at attributes. In the form for the end-user, I am displaying start_at using the standard datetime_select, but I'd rather not have a second datetime select presented to the user. I'm hoping I can create two fields that represent a duration; one for hours, the other for minutes. My question is, ho...

Return Object After Validation Failure

Is there a method to save an object but return the object if it fails the validation_uniqueness_of for a given field? For example, I have the following: class User has_many :words ... end class Word belongs_to :user validates_uniqueness_of :title ... end And I have a situation where I want to either return the Word object if...

interning empty string error

Hey all, Currently, in my request model I have: belongs_to :requestor, :class_name => 'User' So the requestor is the current_user. Problem is when the current_user clicks the create button to submit a form for a request, all of the attributes get updated to the database that are in the form. But since requestor_id is not a valu...

Ajax form not showing up with ruby on rails form_remote_tag

This is all new territory for me, but I am working through a Rails book that was written before start_form_tag was deprecated and I am running into problems with the books example code using remote_form_tag. I have the other forms working but can't get this one up and running. Here's the code: <h1>Categories</h1> <ul id="category_list"...

writing a meta refresh method for rails

I want a method in app/controllers/application.rb that can prepend/append text to whatever template gets rendered. Of course I can't call render twice w/o getting a double render error, so is this possible? I want to redirect after a delay using a meta refresh. Here's what I've got: app/controllers/application_controller.rb: def red...

rails: how to have an image for the submit tag?

I have been using submit tag helpers. <%= submit_tag 'Submit' %> I have an image called my_image.png. How can I make the submit button be an image? I tried: <%= submit_tag '#{image_tag("Login_small.png", :width=>70)}' %> But that doesn't work.. ...

What's a good place for modules in a rails project

I'm adding some non-trivial functionality in my rails application and it needs to be in a module and not one of the auto generated models. I'd like a few suggestions on where the file containing the module should go (currently I've added a 'code' directory on the same level as 'models' and 'views' - but I don't know that that's a strong...

Cancel fragment caching on Exception

If I am caching an rss response like so: <% cache do %> <%= fetch_rss(http://example.org) %> <% end %> how could I prevent it from caching if the rss doesn't return correctly? i.e. if the fetch_rss returns an exception or returns 'Not Found' ...

Generate a thumbnail for the first page of a PDF within a rails App?

Is there anyway to generate a thumbnail image for the first page of an uploaded PDF file. I want to display this image along with the description (provided by the user) of the file. ...

how to set tab to a custom tab using jquery ui and rails

I'm using jqueryUI for tabs on a page. I initialize it like below: $("#tabs").tabs(); <div id="tabs"> <ul> <li><a href="#tabs-4">Part A</a></li> <li><a href="#tabs-2">Part B</a></li> <li><a href="#tabs-5">Part C</a></li> </ul> <div id="tabs-4"> ..... </div> <div id="tabs-2"> .... </div> ...

how to set custom tab in jquery ui and use with rails

I'm using jqueryUI for tabs on a page. I initialize it like below: $("#tabs").tabs(); <div id="tabs"> <ul> <li><a href="#tabs-4">Part A</a></li> <li><a href="#tabs-2">Part B</a></li> <li><a href="#tabs-5">Part C</a></li> </ul> <div id="tabs-4"> ..... </div> <div id="tabs-2"> .... </div> ...

Bundler isn't loading gems

I have been having a problem with using Bundler and being able to access my gems without having to require them somewhere, as config.gem used to do that for me (as far as I know). In my Rails 3 app, I defined my Gemfile like so: clear_sources source "http://gemcutter.org" source "http://gems.github.com" bundle_path "vendor/bundler_gems"...

In which order Rails does the DB queries

In http://stackoverflow.com/questions/2170001/select-n-objects-randomly-with-condition-in-rails Anurag kindly proposed this answer to randomly select n posts with votes >= x Post.all(:conditions => ["votes >= ?", x], :order => "rand()", :limit => n) my concern is that the number of posts that have more than x votes is very big. what ...

MySQL/Rails Version Control for CMS - How is it usually done?

How do projects like BrowserCMS for Rails implement version control for a CMS? What is best practice for version control with database content? How does it relate to git/svn? ...

Filtering join table in has_many :through in RoR

I have the following models in which I join the Language and Products table via the Translation table using the Rails has_many :through paradigm: class Language < ActiveRecord::Base has_many :translations has_many :products, :through => :translations end class Translation < ActiveRecord::Base belongs_to :product belongs_to :lan...

Joining a table with itself via many-to-many in Rails

In my database, OptionSets are associated with other OptionSets. If I was joining two separate tables I would create a simple join table. However, Rails likes to have its foreign keys named <singular_table_name>_id, i.e. optionset_id. However, if I am joining the table with itself I obviously cannot give the two tables the same name. ...

Escaping quotes from Rails Variables when using them for Javascript?

Hi, I am having problems when trying to use a rails variable within javascript code. For example, I might define a link_to_remote, with parameter :complete => "alert('my_var');" If my_var = "I'm testing.", then the javascript code will break due to the single quote closing the code prematurely. If I try using escape_javascript(my_var)...

Rails map.resources & Helper Urls

I have two models like this: class Topic < ActiveRecord::Base has_many :articles end class Article < ActiveRecord::Base belongs_to :user belongs_to :topic has_many :comments end I have setup the resource mapping like so: map.resources :topics do |topic| topic.resources :articles end And I can view the articles just fine ...

Debugging Stale Ruby Process

Hi, I have a ruby script inside a Rails project. The script includes environment.rb so that Rails gets loaded etc. It then listens to data on a TCP socket of another server, parsing it to keep a mysql database up to date. I'm using the daemons gem to be able to start and stop the process easily. Iv had the script running in production w...