ruby-on-rails

rails how to know when send_file done

As it takes some time to prepare the content of the data to be downloaded, I want to show a message "Preparing file to download" when the user submits the request Then when the file is ready, I use send_file to send the data Once it's done, I need to clear the message Thanks a lot ...

What is causing this error when I try to edit a RoR object that was created via scaffold?

What is causing this error when I click on the edit button for a note? The delete button works fine. I created the note object with a scaffold. index.html.erb <% @notes.each do |note| %> <%= note.detail %> <%= button_to 'Delete', note, :confirm => 'Are you sure?', :method => :delete %> <%= button_to 'Edit', edit_note_path(n...

Combine two ActiveRecord Query results

I currently have two active record queries that I would like to combine together joins("join relationships ON user_id = followed_id"). where("follower_id = #{user.id}") and where(:user_id => user.id) Basically I want the results of the second one to appear with the first similar to a UNION statement in SQL. Can it b...

How to use i18n_routing gem with rails2

Hello all, I installed the following gems in addition to rails 2.3.5: i18n (0.4.1) i18n_routing (0.3.7) In environment.rb I added require i18n_routing Inserted the following lines in routes.rb: map.localized(I18n.available_locales, :verbose => true) do map.resources :users map.resource :contact end but when I restart the se...

How do I add a default value to a field in a RoR migration?

How do I add a default value to an existing field in a RoR migration? ...

Rails 3 vs Sinatra

For my next web application, I'm debating whether to use Rails 3.x or Sinatra. I would like to use the server to provide user authentication, application-triggered emails, a fairly complex data model (behind ActiveRecord), and a JSON data interface with the web client. The client side will use static HTML, static CSS, Javascript/jQuer...

Translating rails queries for sqlite.

How would i translate these mysql queries to work with sqlite3?: self.find(:first, :conditions => ['concat(first_name, \' \', middle_names, \' \', last_name) = ?', name]) self.find(:all, :conditions => ['(concat(first_name, \' \', last_name) LIKE ?) OR (concat(first_name, \' \', middle_names, \' \', last_name) LIKE ?)', "%#{name}%", "%...

Displaying RoR relationship

I have setup a model relationship and all is working well when I use code similar to: @parent.child.each do |item| item.name end But how would I call just a specific child given there id eg. Child ID is 14 Would like a call like: @parent.child[childid].name #>>>>>> CHILD'S NAME ...

Javascript not being rendered at script but as html instead

This question is to piggy back off of a previous one I asked yesterday, which deals with moving the create/edit feature of a model onto its index page. One last issue I am having is that I when I go to delete a model, I have some javascript that is supposed to run that reloads the list of models to reflect the change in the database. Thi...

where to put controller code for partials you render from different views in Ruby on Rails

A newbie question: I have a partial that I'm loading on a website on different pages. That partial needs some data, so in the controller of the parent view I do the query: @properties = Property.find(:all) I pass the query results to the partial in the view using :locals Now, I would like to render the same partial from another view....

Rails 2.3.8 Association Problem has_many belongs_to

Hi, I'm new to Rails. I have two models, Person and Day. class Person < ActiveRecord::Base has_many :days end class Day < ActiveRecord::Base belongs_to :person has_many :runs end When I try to access @person.days I get an SQL error: $ script/consoleLoading development environment (Rails 2.3.8) ree-1.8.7-2010.02 > @person = Per...

Changing Rails Query to Pure SQL

I'm looking to move the following code away from ActiveRecord to pure SQL for a performance increase. What would be the best way to write this query in pure SQL (MySQL DB)? User.count(:conditions => ["email = ?",params[:email]]) > 0 Thanks ...

Importing issues for products

Ok so I am trying to import a csv which I need to insert into a db through rails or anyway that would be quickest so i decided to create a dummy rails application to do the importing. Here is some of the code below which I got some of it from a blog I was reading. def upload table = ImportTable.new :original_path => params[:upload][:c...

Sorting Items in Rails Controller Method

I'm having an issue writing a controller action that takes Post ids passed as a parameter and sorts them into a specific order before publishing them. The Posts have a position attribute (I'm using acts_as_list for sorting), and are either published or unpublished (searchable with the named_scopes Post.published and Post.unpublished, ac...

rails validation on accepts_nested_attributes_for and habtm association in an update resets the association

In rails 2.3.8 I am having trouble with validations on a accepts_nested_attributes_for association if I loop through or even inspect the habtm association in validation the lessons are loaded and any updates are lost. For example, I have the following schema: ActiveRecord::Schema.define(:version => 20100829151836) do create_table "att...

nginx passenger expires max cached pages

I have posted another question similar to this, which I thought I resolved. But it is coming back with another symptom. I am using REE/Passenger/Nginx and have the following in my nginx.conf location ~* ^.+.(jpg|jpeg|gif|png|css|js|swf)?([0-9]+)?$ { expires max; passenger_enabled on; } Ever since I did this, it seems ...

Calling new on the db string name

Ok so i have the string "Product". table_name = "Product" I cant do table_name.new undefined method `new So i was trying to find a work around like this table_name = table_name.downcase.pluralize name = ActiveRecord::Base.connection.tables.select { |t| t == table_name }.first name.new I am not sure this will work but even ...

How to format a number in a ruby on rails controller, number_with_delimiter works only in views

I would like to format a number in a controller before inserting it into a string. But the function number_with_delimiter() does not work in a controller. I need the string to send to a javascript plugin. I could run the code in the view, but I guess that is not the best option. @mycarousel_itemList = @mycarousel_itemList + "{url: '" +...

Adding Google Maps (API V3) support to a Ruby on Rails app

Hi there, I'm searching for a good solution for integrating google maps into a ruby on rails 2.3 app. I know there's a project called ym4r but it seems old and not so maintained. Should I use directly the Google API itself? Thanks! ...

Stripping the first character of a string

i have string = "$575.00 " string.to_f // => 0.0 string = "575.00 " string.to_f // => 575.0 the value coming in is in this format and i need to insert into a database field that is decimal any suggestions "$575.00 " ...