Rails

ExecJS::RuntimeUnavailable error when I start the Rails server

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have created a new Rails application. When I try to start the server I get the following error: [bathakarai@Project1-CO samp]$ rails server /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/script_rails_loader.rb:11: warning: Insecure world writable dir /usr in PATH, mode 040777 /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:216: warning: Insecure world writable dir /usr in PATH, mode 040777 /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in

Understanding rails migration statement (:null => false)

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to understand the following statement, it is from a rails migration file: x.datetime "new", :null => false x.datetime "update", :null => false I understand the the first part of both statements (everything before the comma) but I am unsure on the null portion :null => false Is this basically saying "if it does not exist, then it is false?" The logic just seems a bit strange, any clarification on this would be greatly helpful. 回答1: Edit: I had taken the question to be about syntax and translation since it originally mentioned

Can Rails automatically parse datetime received from form text_field

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can Rails automatically parse a datetime received from a form's text_field? # in view <div class="field"> <%= f.label :created_at %><br /> <%= f.textfield :created_at %> </div> # in controller params[:product][:updated_at].yesterday Currently I'm get following error: undefined method `yesterday' for "2010-04-28 03:37:00 UTC":String 回答1: If you are putting that param into a model directly, as the rails generator boilerplate code does, ActiveRecord takes care of that for you def create @product = Product.new(params[:product]) @product.updated

Called id for nil in Rails 3

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In development mode: nil.id => "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id" In production mode: nil.id => 4 Why? 回答1: Look for the line that says the following in your environments configs: # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # or false in production.rb This is to prevent you from calling methods on nil while in development mode. I guess they disabled it for performance reasons in production. And nil is a singleton object in ruby,

Rails rendering instance variable from application.html.erb

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am following the Agile Web Development with Rails 4 book and I'm a bit confused on a part about rendering. The simple version of the question is... within the application.html.erb file there it says render @cart This is confusing because I thought that there needed to be a controller associated with that view in order to know which partial and @cart variable to use. Is it simply by naming convention that this line looks for a partial like _cart.html.erb? And in that case does it not actually know what @cart is until it renders that partial

Rails 4 Use Factory Girl factories from Engine

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've created a rails engine (full, not mountable) to provide models to a number of different rails apps. I use Factory Girl Rails to test this engine and the tests all run fine for the engine itself. I now want to be able to use these factories in other apps that include this engine. The dependencies for the Gemspec look like this: s.add_dependency "rails", "~> 4.0.3" s.add_dependency "mysql2", "~> 0.3.15" s.add_development_dependency "rspec-rails", "~> 3.0.0.beta" s.add_development_dependency "factory_girl_rails", "~> 4.4.1" s.add

Ruby: stack level too deep (SystemStackError)

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Ruby is crashing in Cygwin for rails and bundler. $ ruby -v ruby 1.9.3p374 (2013-01-15 revision 38858) [i386-cygwin] Chloe@dumbopc /cygdrive/c/Sites $ rails -v Rails 3.2.11 Chloe@dumbopc /cygdrive/c/Sites $ cd testapp Chloe@dumbopc /cygdrive/c/Sites/testapp $ rails -v /usr/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:114: stack level too deep (SystemStackError) Chloe@dumbopc /cygdrive/c/Sites/testapp $ bundle install Fetching gem metadata from https://rubygems.org/........... Fetching gem metadata from https://rubygems.org/..

Returning files from rails

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Beginner rails question: How does one return a file from a controller in rails? I'm familiar with returning/rendering JSON objects. However I've never returned/rendered a file w/ an arbitrary extension. From reading around SO it sounds like render :nothing => true could help. I'm just looking for some guidance or relevant documentation. 回答1: You can use the built-in rails send_file or send_data method. To stream a file (e.g. for a file proxy endpoint), use send_file: send_file ( "#{RAILS_ROOT}/path/to/file/on/server" , : filename =

Rails model validators break earlier migrations

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a sequence of migrations in a rails app which includes the following steps: Create basic version of the 'user' model Create an instance of this model - there needs to be at least one initial user in my system so that you can log in and start using it Update the 'user' model to add a new field / column. Now I'm using "validates_inclusion_of" on this new field/column. This worked fine on my initial development machine, which already had a database with these migrations applied. However, if I go to a fresh machine and run all the

Rails has_many :through saving additional fields

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to find a graceful way of saving an additional field called description on the Appointment model (below). My models are setup like this: class Physician < ActiveRecord :: Base has_many : appointments has_many : patients , through : : appointments end class Appointment < ActiveRecord :: Base belongs_to : physician belongs_to : patient end class Patients < ActiveRecord :: Base has_many : appointments has_many : physicians , through : : appointments attr_accessible : name end In my view I have checkboxes setup to save the