ruby-on-rails-3

On Heroku, Cedar, with Unicorn: Getting ActiveRecord::StatementInvalid: PGError: SSL SYSCALL error: EOF detected

为君一笑 提交于 2019-12-29 06:14:43
问题 Heroku support says this has to do with their version of libssl on shared databases, but we've encountered it on a project that's on a dedicated database, too. Basically this error happens every so often (closer to just after a deploy) on every project we've moved to the new Cedar stack with Unicorn configured to 3 workers: Error Message: ActiveRecord::StatementInvalid: PGError: SSL SYSCALL error: EOF detected : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull

Handling jsonp in rails 3 controller

我与影子孤独终老i 提交于 2019-12-29 05:33:12
问题 I want my controller action to handle jsonp requests from jquery $.getJSON . In my controller action i have the following respond_to block: respond_to do |format| format.html { render json: {:items_by_tag => @tagged_item_list}} if params[:callback] format.js { render :json => {:items_by_tag => @tagged_item_list}.to_json, :callback => params[:callback] } else format.json { render json: {:items_by_tag => @tagged_item_list}} end end But I'm getting SyntaxError:invalid label when i call the url

Order array. undefined method `order' for Array. Convert array into hash?

我的未来我决定 提交于 2019-12-29 05:25:16
问题 I have a City model and in city's show action I want to render hotels nearby specific locations in the city. Cities has_many locations; hotels are being searched using Geocoder near method. To add order functionality I've followed Ryan Bates screencasts #228, but this approach doesn't seem to work with arrays, giving error undefined method `order' for #< Array:0x007f960d003430> cities_controller.rb helper_method :sort_column, :sort_direction def show session[:search_radius] = 2 if session[

Rails 3's “bundle install” and “bundle install --deployment” both work well except the 2nd one just uses more disk space?

笑着哭i 提交于 2019-12-29 04:17:08
问题 It seems that on development machines (like on the Macbook), if we use bundle install --deployment , all the gems will be installed into the vendor/bundle folder and it just use more disk space if we have multiple Rails 3 projects (some project just for testing Rails 3). If it is not --deployment , then the gems will be in the "generic" folder instead of inside the project folder, and so can be shared across projects. Is this true? Another thing is, do we need to add all files under vendor

Devise routing: is there a way to remove a route from Rails.application.routes?

落爺英雄遲暮 提交于 2019-12-29 03:36:12
问题 devise_for creates routes including a DELETE route, which we want to remove, and devise_for doesn't support an :except or :only option. How can I remove a route from Rails.application.routes ? Either in the draw block, or afterward? Here are details of a bug, which was the reason we needed to remove the route. we were issuing a DELETE request to a custom UJS controller action in the controller action we were removing what we wanted to, then doing a 302 redirect. This was a bad idea, and we

jQuery ajax request not triggering JS response from rails controller?

我的梦境 提交于 2019-12-29 03:33:33
问题 I have a standard controller which is set up to respond to HTML, JS and JSON requests: def picture @picture = Picture.new params[:picture] respond_to do |format| if @picture.save format.html do logger.debug "In the HTML responder" redirect_to @picture end format.json { render json: @picture, status: :created, location: @picture } format.js { render :nothing => true } else # you get the idea end end end Now I'm trying to send a request to that controller with the $.ajax function (I can't use

RoR differences between :url, :action, :method in form_for

眉间皱痕 提交于 2019-12-29 03:10:26
问题 There might be answers in documentation, but i don't seem to find good answers. So among the three :url, :action, :method, what are their differences when used in form_for in Rails? 回答1: Difference between :url , :action and :method :url If you want to submit your form for any particular controller, any particular action and want to pass some extra parameter (use action that define in controller that you pass on controller ) for example <%= form_for @post, :url => {:controller => "your

How to use unscoped on associated relations in Rails3?

时光毁灭记忆、已成空白 提交于 2019-12-29 02:47:47
问题 I have a default scope on products due to information security constraints. class Product < ActiveRecord::Base has_many :photos default_scope where('visible = 1') end In my associated Photo model, however, I also have to find products that should not be visible. class Photo < ActiveRecord::Base belongs_to :product end my_photo.product In other cases, I can use unscoped in order to bypass the default_scope, e.g. in Product.unscoped.find_by_title('abc') . However: How to remove the scope when

Exclude application layout in Rails 3 div

痴心易碎 提交于 2019-12-29 02:10:25
问题 I'm loading a template profile_messages as part of jQuery UI Tabs with Ajax. However when it loads, profile_messages inherits my site's application layout (header, footer, everything). I tried doing it as a partial but then things didn't work. So I'm wondering if there was a way to do it. The jQuery in my application.js : $(function() { $( "#tabs" ).tabs({ ajaxOptions: { error: function( xhr, status, index, anchor ) { $( anchor.hash ).html( "There was an error loading this tab. Please try

group by + sum on multiple columns in rails 3

纵然是瞬间 提交于 2019-12-29 00:40:30
问题 I need to get a list of locations ordered by the number of picture that I have in the DB for these locations, here is my query Location.select(:city).group(:city).order("SUM(images_count) DESC").sum(:images_count) This worked like a charm, unfortunately, I now need to add province and country to prevent ambiguities to arise, so I now have this Location.select(:city, :province, :country).group(:city, :province, :country).order("SUM(images_count) DESC").sum(:images_count) And this is not