ruby-on-rails-3.2

Turbolinks with carrierwave images as CSS background-image

风流意气都作罢 提交于 2019-12-03 11:11:50
I've been using turbolinks along this year but lately I'm getting this annoying bug. Images uploaded via carrierwave are loaded in the site with absolute URL's in the first request, but when you start browsing in the site via turbolinks, all carrierwave images change to relative paths. <%= image_tag "image.jpg %> elements work ok, but the images are loaded as CSS background-image, they don't appear. This apparently happens only on chrome (I have Versión 31.0.1650.57 m). I made a trace via console and all images are loaded in the document, so I went to the Inspector and disabled/enabled the

how to use rails format.json [closed]

眉间皱痕 提交于 2019-12-03 11:08:13
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. def index @cellphones = Cellphone.all respond_to do |format| format.html # index.html.erb format.json { render json: @cellphones } end SIMPLE ANSWERS PLEASE... what is format.json used for? do I have to create a view for it? how does it relate to javascrip ?

Rails emits warning: “Rack::File headers parameter replaces cache_control after Rack 1.5”

早过忘川 提交于 2019-12-03 10:22:23
问题 I've recently upgraded my Rails to v3.2. The server starts and works, however I'm noticing the following warning: Rack::File headers parameter replaces cache_control after Rack 1.5. In my development.rb I have the following configuration for cache control: config.static_cache_control = "public, max-age=36000" What does the warning mean and what should I do to address it? 回答1: The warning is caused by a call from within Rails itself. The warning has been fixed in Rails 3.2.13. 回答2: You have to

rake db:migrate error (Function 'inotify_init' not found)

拟墨画扇 提交于 2019-12-03 10:04:12
I just got done setting up my rails environment on my old mac book and ran into this error. I've installed FFI and rb-inotify. I've also ran bundle install again. I've looked at https://github.com/ffi/ffi/issues/66 and https://groups.google.com/forum/?fromgroups=#!topic/ruby-ffi/gj3_k34o80k which both indicate that this is a linux specific API. There is a suggestion on the second of those links that says I should just remove that gem and things that depend on it, but I am hesitant to remove FFI which seems to depend on it. What course of action do you suggest? Any advice on this matter is

Rails 3 - set the filename in a respond_to

Deadly 提交于 2019-12-03 10:01:37
This seems like it should be simple, but I can't seem to find a straight answer. I have added a csv mime-type, and the following seems to work, except that the downloaded file is always named "report.csv". In my controller: def report respond_to do |format| format.html format.csv do render :template => "summary/report.csv.erb", :filename => "foo" #doesn't work end end end I think it's using the default renderer (I haven't implemented an alternate renderer), but I can't seem to find complete docs on the options available. Isn't there something like a "filename" option or something that I can

How to create another object when creating a Devise User from their registration form in Rails?

折月煮酒 提交于 2019-12-03 09:08:43
There are different kinds of users in my system. One kind is, let's say, a designer: class Designer < ActiveRecord::Base attr_accessible :user_id, :portfolio_id, :some_designer_specific_field belongs_to :user belongs_to :portfolio end That is created immediately when the user signs up. So when a user fills out the sign_up form, a Devise User is created along with this Designer object with its user_id set to the new User that was created. It's easy enough if I have access to the code of the controller. But with Devise, I don't have access to this registration controller. What's the proper way

Adding index :unique to a column in ruby on rails via generate migration

只谈情不闲聊 提交于 2019-12-03 08:45:50
问题 I know that i can touch a migration and add add_index :table_name, :column_name, :unique => true But how is the right rails migration command to generate this? rails g migration add_index_to_column_name :column_name, :unique => true Is that right? In my special example I have a table customers t.integer :customerID t.string :surname t.string :first_name t.string :phone an i want to set the customerID to unique. Tried rails g migration AddIndexToCustomers :customerID, :unique => true But if i

Rails Render Partial in Helper

邮差的信 提交于 2019-12-03 08:41:11
I have been trying to render one of my partials in a helper function located within my controller. The first issue I encountered was that the helper was returning the each loop instead of the result of the loop. To remedy this I attempted to have it return a string containing the results of the loop. def display_replies(comment) if comment.replies.count > 0 string = "" comment.replies.each do |reply, index| string = string + (render partial: "comment", locals: {index: index}).to_s.html_safe end string end Called in View with <%= display_replies(reply) %> When I look at my view, what is

How to download a CSV file in Ruby on Rails?

こ雲淡風輕ζ 提交于 2019-12-03 08:39:54
问题 In my InvoicesController I have this: def index @invoices = current_user.invoices respond_to do |format| format.html format.xls format.csv # not working! end end In my index.html.erb view I have these two download links: <%= link_to "Download as Excel", invoices_path(:format => "xsl") %> <%= link_to "Download as CSV", invoices_path(:format => "csv") %> The templates index.xsl.erb and index.csv.erb do exist as well. The first link works, i.e. the Excel file gets downloaded to the user's

How to find current connection pool size on heroku

旧时模样 提交于 2019-12-03 08:30:03
问题 We have a rails 3.2(.11) app with many dynos running on the heroku bamboo stack, connecting to a MySQL RDS server. There seem to be some issues with our current database connections, so we are trying to debug exactly how many connections each dyno is spinning up. I know I can set the size of a connection pool in the DATABASE_URL config on heroku, but can't seem to find out how many connections are currently being used by default. Two main questions: 1) How can I find the size of the