ruby-on-rails-3.2

Helpers use a lot of memory in rails 3(.2)

江枫思渺然 提交于 2019-12-04 10:56:57
While migrating a rails 2 app to rails 3 I encountered a huge increase in memory used. After some research I found out the helpers were the problem. Uncommenting any helpers in the view would speed everything up. Things I tried to find the real issue: include_all_helpers = false disable parts of the helper files clean up the code by refactoring Model.all usages to some faster code I got a theory now that some helpers might be renamed or deleted, rails starts to search for them and starts searching models / controllers as rescue. A page request takes up to 5 seconds and using 2 GB of memory.

Rails send_file don't play mp4

女生的网名这么多〃 提交于 2019-12-04 10:45:15
I have a Rails app that protects the uploaded videos putting them into a private folder. Now I need to play these videos, and when I do something like this in the controller: def show video = Video.find(params[:id]) send_file(video.full_path, type: "video/mp4", disposition: "inline") end And open the browser(Chrome or FF) at /videos/:id it doesn't play the video. If I put the same video at the public folder, and access it like /video.mp4 it will play. If I remove the dispositon: "inline" it will download the video and I can play it from my computer. Samething happens with webm videos. What am

Rails :confirm modifier callback?

我是研究僧i 提交于 2019-12-04 10:29:56
问题 I want to call a javascript function that will be conditional upon a user's response to the confirm box. For example, I have the following anchor: <%= link_to 'Sign Out', destroy_session_path, confirm: 'Are you sure that you would like to sign out?', method: :delete %> Should I just abandon the unobtrusive javascript and bind my own jQuery callback to my anchor? Or is there some magical way to pass a callback function to the Rails url helper? I did not see any discussion of callbacks in the

rails callbacks not getting executed

筅森魡賤 提交于 2019-12-04 10:27:38
For my life I trying to find out why are my callbacks are not getting executed sometimes (you heard it right sometimes as most of time it works out of the box) All I have is parent/child relations between 2 models upon creation of child record all I'm doing in after_create callback is update(accumulate all child amount in parent field to avoid heavy query at run time) the amount field in parent table/ model record Parent model( Payout ) Child model is ( Sales Transaction ) Payout has_many SalesTransactions as said above upon creation of sales transaction I'm updating(incrementing to be precise

How can I find a memory leak on Heroku?

筅森魡賤 提交于 2019-12-04 09:04:30
问题 I have a Rails 3.2.8 app running on Heroku Cedar with Ruby 1.9.3. The app runs fine when it launches but after a day or so of continuous use, I start to see R14 errors on my logs. Once the memory errors start, they never go away, even if the app is idle for several hours. Shouldnt the garbage collector clean up unused objects after a while and reduce the memory load? It seems this is not happening on Heroku. Generally, memory usage starts to creep up after running some reports with several

undefined method `key?' for nil:NilClass

空扰寡人 提交于 2019-12-04 09:02:31
I'm new to Rails and was following Ryan Bate's tutorial on how to make a simple authentication system ( http://railscasts.com/episodes/250-authentication-from-scratch?autoplay=true ) and I was just going through it but got this error: ` NoMethodError in UsersController#new undefined method `key?' for nil:NilClass Rails.root: C:/Sites/authentication` I don't really know what this means since I'm just a beginner, but these are my files: users controller: class UsersController < ApplicationController def new @user = User.new end def create @user = User.new(params[:user]) if @user.save redirect_to

How to join on subqueries using ARel?

回眸只為那壹抹淺笑 提交于 2019-12-04 08:37:13
问题 I have a few massive SQL request involving join across various models in my rails application. A single request can involve 6 to 10 tables. To run the request faster I want to use sub-queries in the joins (that way I can filter these tables before the join and reduce the columns to the ones I need). I'm trying to achieve this using ARel. I thought I found the solution to my problem there: How to do joins on subqueries in AREL within Rails, but things must have changed because I get undefined

HABTM checkbox in a nested form

≯℡__Kan透↙ 提交于 2019-12-04 08:24:52
I am trying to implement a HABTM checkbox in a nested form. Currently, I have 3 models. Subject, lesson and groups. The associations are as follows: Each subject has many lessons. Each lesson has and belongs to many groups. Right now, I am trying to implement them all on a single creation and edit form. Such that a lesson is nested in the subject and for each lesson there is a list of group check boxes to implement the HABTM relationship. I am facing trouble implementing the HABTM relationship as there are many lessons per subjects and I am not sure how I could distinguish between the

Find records that were created closest to the current date

删除回忆录丶 提交于 2019-12-04 08:24:08
I would like to get the records that have their created_at date closest to the current date. How can I do this with active records' where clause? You could find the closest record in the past with something like: Record.where("created_at <= ?", Date.today).order_by("created_at DESC").limit(1) Similarly, you can have the closest record in the future Record.where("created_at >= ?", Date.today).order_by("created_at ASC").limit(1) And then compare wich one is the closest to current date... There may be a solution to do it with a single request, but I could not find how (if you're using SQL server,

How do I make config.exceptions_app work with rspec

╄→尐↘猪︶ㄣ 提交于 2019-12-04 08:20:21
In my Rails 3.2 app, I'm trying to use config.exceptions_app to route exceptions through the routing table to render error-specific pages (especially one for 401 Forbidden). Here's what I've got so far for configuration: # application.rb config.action_dispatch.rescue_responses.merge!('Error::Forbidden' => :forbidden) config.exceptions_app = ->(env) { ErrorsController.action(:show).call(env) } # development.rb config.consider_all_requests_local = false # test.rb config.consider_all_requests_local = false And now the meat of the matter: module Error class Forbidden < StandardError end end class