Rails

Rails 4 - How to serve video?

匿名 (未验证) 提交于 2019-12-03 02:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Rails 4 for my web application and I'm using VideoJS to display it, like: <video id="video1" class="video-js" controls preload="auto" width="640" height="264" poster="{{pCtrl.video.poster}}" src="<%= @video.file %>"> <source src="<%= @video.file %>" type="video/<%= @video.file.file.filename.last(3) %>"> </video> I was always getting this error from VideoJS: VIDEOJS: ERROR: (CODE:3 MEDIA_ERR_DECODE) The video playback was aborted due to a corruption problem or because the video used features your browser did not support. When I open

Rails 4 Error with every command “`load&#039;: no implicit conversion of nil into String” (Mac OS X 10.9)

匿名 (未验证) 提交于 2019-12-03 02:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've just installed a fresh Ruby on Rails dev stack on my new Macbook, which runs Mac OS X 10.9 Mavericks. Here is my stack: Xcode command line tools Homebrew Rbenv Bundler Ruby 2.1.0 Rails 4.1.1 I ran rails new test_app to generate a first test app. This command successfully completed, but since it, every Rails command I try in my CLI returns this kind of error message: $ test_app > bin/rails server /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load': no implicit conversion of nil

Rails Return multiple content_tags from Helper module

匿名 (未验证) 提交于 2019-12-03 02:22:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've written the following helper: def section_to_html (block) case block[0].downcase when "paragraph" block.shift block.each do |value| return content_tag(:p, value) end end end It is currently parsed these arrays. ["paragraph", "This is the first paragraph."] ["paragraph", "This is the second.", "And here's an extra paragraph."] And it returns: <p>This is the first paragraph.</p> <p>This is the second.</p> Is there a way to accumulate the content_tag? so it returns: <p>This is the first paragraph.</p> <p>This is the second.</p> <p>And here

Sum and Group by in Rails

匿名 (未验证) 提交于 2019-12-03 02:22:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a table defined as such: Name - Order# - Widget Count Bob - 12311 - 6 Nancy- 12555 - 8 BoB - 87573 - 12 Nancy- 12929 - 4 I'd like to retrieve them as such: Bob - 18 Nancy - 12 Ie: A sum of their widget counts, ordered by name. I know how to go about this in SQL server/etc, but I'm not sure what the best practice is in Rails. Any help would be much appreciated! 回答1: This should work, assuming your model is called Person: Person.group(:name).count(:widget_count) You can find more info about it on RailsGuides for ActiveRecord . 文章来源: Sum

ActiveRecord::StatementInvalid: PG::Error: ERROR: null value in column “id” violates not-null constraint

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am getting the following error frequently in my application. If I restart my rails application this error will not appear for some time. Rails - 3.1.3 Ruby - 1.9.3 ActiveRecord::StatementInvalid: PG::Error: ERROR: null value in column "id" violates not-null constraint Directory.create(:name=>"name",:alias_name=>"name",:site_id=>2,:type=>"Directory") (0.3ms) BEGIN SQL (0.8ms) INSERT INTO "databases" ("alias_name", "created_at", "created_by", "id", "name", "site_id", "type", "updated_at", "updated_by") VALUES ($1, $2, $3, $4, $5, $6, $7, $8,

Refused to execute script from &#039;*&#039; because its MIME type (&#039;application/json&#039;) is not executable, and strict MIME type checking is enabled

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am a newbie to AngularJS. I am using a rails application to expose data in json format. The data is to be used by angular app. The angular repo and the rails repo are completely different. The reason for different repositories is because I want my rails repo just to expose data using APIs which i can use in the angular app. My rails controller is as below class Api::V1::PhonesController < ApplicationController def index render json: Phone.all end def show render json: Phone.find(params[:id]) end ... end Now, when i visit 'localhost:3000

Specifying attributes of a Rails object passed into a JSON object

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an object in Rails that has attributes A, B, C, D, and E. When passing this object back to the client-side through a JSON object, how can I tell the rails controller to only include attributes A and D in the JSON object? Within my Users controller, my code is as follows: @user = User.find(params[:id]) respond_to do |format| format.html format.json { render :json => @user} end This code works, however, the JSON object that is returned contains all the attributes of the @user object. How can I limit the attributes that are included in

Cannot get factory_girl running under rails 3.0.5,unexpected tCONSTANT

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is my Gemfile config: group :development, :test do gem 'rspec-rails' gem 'factory_girl', '~>2.0.0.beta1' gem 'factory_girl_rails', :git => 'https://github.com/thoughtbot/factory_girl_rails.git', :tag => 'v1.1.beta1' end This is my spec_helper.rb : # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require "factory_girl" # Requires supporting ruby files with custom matchers and macros, etc, # in spec

How to monitor delayed_job with monit

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Are there any examples on the web of how to monitor delayed_job with Monit ? Everything I can find uses God , but I refuse to use God since long running processes in Ruby generally suck. (The most current post in the God mailing list? God Memory Usage Grows Steadily .) Update: delayed_job now comes with a sample monit config based on this question. 回答1: Here is how I got this working. Use the collectiveidea fork of delayed_job besides being actively maintained, this version has a nice script/delayed_job daemon you can use with

Rails 4 Controller Test “Undefined Method Permit”

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a simple controller test based on the Rails 4 docs (using Test::Unit): test "should create user" do assert_difference ( 'User.count' ) do post : create , user : users (: sample_user ) end assert_redirected_to user_path ( assigns (: user )) end And, despite the actual user being created just fine, the test fails, saying: 1) Error: UsersControllerTest#test_should_create_user: NoMethodError: undefined method permit' for "832959492":String app/controllers/users_controller.rb:23:in user_params' app/controllers/users_controller.rb