你认为将.gitignore变成Git仓库是一种好习惯吗?
有些人不喜欢它,但我认为它很好,因为你可以跟踪文件的历史记录.不是吗?
这是我在命令提示符之前看到的最后一件事:
Searching for binary rubies, this might take some time.
Found remote file https://rvm.io/binaries/osx/10.9/x86_64/ruby-2.1.1.tar.bz2
Checking requirements for osx.
About to install Homebrew, press `Enter` for default installation in `/usr/local`,
type new path if you wish custom Homebrew installation (the path needs to be writable for user)
: Requirements installation failed with status: 1.
Run Code Online (Sandbox Code Playgroud)
我认为它没有达到我按Enter键的程度
我已经生成了一个新的rails 4(rc1)项目,使用rails new并生成了一个脚手架rails g scaffold.
正如预期的那样,它创建了迁移,控制器和所有必需的视图文件.
它还创建了show.json.jbuilder和index.json.jbuilder.
我假设这是为了帮助模型生成json.控制器也包含format.json调用.
问题:为什么它需要json以及生成的应用程序的哪个部分使用json?它看起来不像(对我来说)视图使用json渲染任何东西,似乎它们在服务器端呈现(@model变量在视图中用于获取内容).
边缘指南(http://edgeguides.rubyonrails.org/)没有提到jbuilder以及为什么需要它.
提前致谢!如果我能澄清这个问题,请告诉我.
我的控制器中有以下内容:
redirect_to signin_path, :notice => "The email is already registered"
Run Code Online (Sandbox Code Playgroud)
在我看来,我有
<%= flash[:notice] if flash[:notice] %>
Run Code Online (Sandbox Code Playgroud)
但是没有出现flash消息.
但是,如果我在控制器中执行以下操作
flash[:notice] = "There is already an acount for this email. Please Login to create your board."
redirect_to signin_path
Run Code Online (Sandbox Code Playgroud)
它确实有效.第一个不起作用的原因是什么?
我在Ruby中学到了两种数组排序方法:
array = ["one", "two", "three"]
array.sort.reverse!
Run Code Online (Sandbox Code Playgroud)
要么:
array = ["one", "two", "three"]
array.sort { |x,y| y<=>x }
Run Code Online (Sandbox Code Playgroud)
我无法区分这两者.哪种方法更好,它们在执行方面究竟有何不同?
我最近每次更改代码时都开始重新启动开发服务器.我的development.rb文件仍然有这一行:
config.cache_classes = false
我尝试使用调试器验证此值是否已停留.为此,我将配置设置为environment.rb中的全局变量:
$my_initializer = Rails::Initializer.run do |config| ... end
然后我debugger在我的一个控制器中放了一条线,所以我可以这样做:
(rdb:2) $my_initializer.configuration.cache_classes false
这样就消除了将价值cache_classes设定在true其他地方的可能性.我已经尝试过使用Mongrel和WEBrick,但它仍然会发生.
还有什么可能导致Rails不能在每次请求时重新加载我的代码?
我正在运行:Mongrel 1.1.5
WEBrick 1.3.1
Rails 2.3.8
Ruby 1.8.7 p253
编辑:在@Daemin的建议下,当我将它们保存在我的文本编辑器(Textmate)中时,我检查了我的文件的mtime实际上是否正在更新
merced:controllers lance$ ls -l people_controller.rb -rwxr-xr-x 1 lance staff 2153 Act 10 18:01 people_controller.rb
然后我做了一个更改并保存了文件:
merced:controllers lance$ ls -l people_controller.rb -rwxr-xr-x@ 1 lance staff 2163 Oct 11 12:03 people_controller.rb
所以这不是mtimes的问题.
我知道这可能是一个简单的问题,但我很难过.
我正在处理的应用程序包含如下资产:
app
--assets
----fonts
----images
----javascripts
Run Code Online (Sandbox Code Playgroud)
我喜欢有效地组织资产以避免混乱,所以我试图像这样分解图像:
app
--assets
----fonts
----images
------icons
------views
--------home
--------admin
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想引用图像,image.png而不必在资产前添加文件夹路径views/home/image.png,我相信尽管不能像开箱即用那样设置.
我目前正在阅读迈克尔·哈特尔的RoR教程,并且在尝试运行Spork和Guard时陷入了第3章.当我尝试运行测试时,我得到:
/bin/sh: rspec: command not found
是的,我确实环顾四周寻找答案,但我没有看到RubyTest.sublime.settings文件在哪里,所以我不知道如何编辑它.任何人都可以帮我解决如何解决我的错误?
这是我的用户fodler中的Rubytest.sublime.settings文件
{
"erb_verify_command": "bundle exec erb -xT - {file_name} | ruby -c",
"ruby_verify_command": "bundle exec ruby -c {file_name}",
"run_ruby_unit_command": "bundle exec ruby -Itest {relative_path}",
"run_single_ruby_unit_command": "bundle exec ruby -Itest {relative_path} -n '{test_name}'",
"run_cucumber_command": "bundle exec cucumber {relative_path}",
"run_single_cucumber_command": "bundle exec cucumber {relative_path} -l{line_number}",
"run_rspec_command": "bundle exec rspec {relative_path}",
"run_single_rspec_command": "bundle exec rspec {relative_path} -l{line_number}",
"ruby_unit_folder": "test",
"ruby_cucumber_folder": "features",
"ruby_rspec_folder": "spec",
"ruby_use_scratch" : false,
"save_on_run": false,
"ignored_directories": [".git", "vendor", "tmp"],
"hide_panel": false,
"before_callback": "", …Run Code Online (Sandbox Code Playgroud) 我有一个自定义验证方法,我只想在create上执行:
validate :post_count, :on => :create
def post_count
# validate stuff
end
Run Code Online (Sandbox Code Playgroud)
但是,它在更新时被激活(除了在创建时).
该:on => :create选项不适用于自定义验证方法吗?
ruby的SecureRandom.uuid(Ruby 1.9.3)和UUID gem之间有区别吗?UUID宝石是"老"的做事方式吗?
从我收集的文档中,gem更加"安全"成为一个真正独特的UUID,而SecureRandom.uuid更像是一个随机字符串,它更有可能不是唯一的.另外,UUID似乎允许基于文件的持久性来帮助解决这个问题.
因此,我希望能听到一些比我更有洞察力的人.