一些具体的 Rails 问题
我有几个具体问题。我尝试过谷歌搜索这些内容,但我得到了很多非常一般的信息。我也看过教程,但通常它们太长了,我找不到我的具体问题。
谢谢!
- :test、:development 和 :assets 之间有什么区别? Rails 3.2.1 组:开发,:测试,但在我正在观看的“Rails 3 教程”视频中,他将它们分开。
- 你通常会写多少个测试?看来你可以写 5... 或无限。甜蜜点在哪里?
- 我使用哪个 javascript 文件夹?我注意到有一个公共文件夹,然后有一个文件夹,我可以将东西放入名为“javascript”和“images”的资产下。我是否需要使用这些资产文件夹,或者可以将“js”和“img”(我的首选命名约定)放在 /public 中
- 如何编译脚本/样式表?我注意到 uglifier 在那里,是否有一些命令可以压缩 css 和 js 并将它们合并到一个文件中? (一个 css,一个 js)
- 每当我运行 Rails 控制台时如何运行命令?我知道如何将
gem 'hirb'
放入Gemfile中,但我想每次为该项目运行rails console时都运行extend Hirb::Console
,所以我不这样做必须输入它,我可以很好地生成我的表格
I have a few specific questions. I have tried googling these but I get a lot of extremely general info. I've also looked at tutorials but generally they are so long I can't find my specific Question.
Thanks!
- what is the difference between :test, :development and :assets? Rails 3.2.1 groups :development, :test but in the "Rails 3 Tutorial" videos i'm watching he breaks them out separately.
- how many tests do you usually write? It seems you could write 5... or infinite. Where is the sweet spot?
- which javascript folder do I use? I notice there is a public folder and then theres a folder i can place stuff into under assets called 'javascript' and 'images'. Do i need to use those assets folders or is it ok to put 'js' and 'img' (my preferred naming convention) inside of /public
- how do i compile scripts/stylesheets? I noticed uglifier is in there, is there some command that compresses css and js and combines them into one file? (one css, one js)
- how do i run commands whenever i run rails console? I know how to put
gem 'hirb'
in Gemfile, but I want to runextend Hirb::Console
every time rails console is run for that project so I don't have to type it, and i can generate my tables nicely
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我同意 JacobM 上面在评论中所说的,但也许我可以为你总结一下。
这个问题有点含糊。您指的是 Rails 环境还是指 Gemfile?我假设您指的是
Gemfile
。在这种情况下,组:资产做
宝石“链轮”
gem '资产-ftw'
end
是告诉捆绑器何时包含这些 gem 的一种方式。您的
:development
配置文件中不需要:testing
gem,反之亦然,等等。它的组织良好。这个问题没有硬性或快速的答案。这实际上取决于您正在编写的代码。建议彻底测试。确保您的单元测试涵盖模型的所有方面,并使用集成测试来确保用户操作在堆栈中成功完成。
我建议不要重命名
/assets
目录中的文件夹,但 Rails 可能允许您这样做。当 Rails 应用程序投入生产时,资产文件夹中找到的文件将被压缩。/public/javascripts
文件夹是在 Rails3.1
之前用于驻留
.js
文件的位置,要编译资源,请运行 rake 命令 < code>rake assets:precompile
我不确定。
以获得更完整的答案。我会把这些分成更长的问题,但搜索得更彻底,因为我认为其中大部分问题以前都被问过。
I agree with what JacobM said above in a comment, but perhaps I can sum these up for you.
This question is slightly vague. Are you referring to rails environments or are you referring to the
Gemfile
? I am going to assume you mean theGemfile
. In that case, thegroup :assets do
gem 'sprockets'
gem 'assets-ftw'
end
is a way of telling bundler when to include those gems. You don't need
:testing
gems in your:development
profile, and vice versa, etc. Its good organization.This question doesn't have a hard or fast answer. It really depends on the code you are writing. It is advised to test completely. Make sure your unit tests cover all aspects of your model and using integration testing to ensure user actions are completing successfully up and down the stack.
I would advise against renaming the folders inside the
/assets
directory, but rails may let you do that. The files found in the assets folder are their to be compressed when the rails app is put into production. The/public/javascripts
folder is where.js
files used to reside before Rails3.1
To compile assets you run the rake command
rake assets:precompile
I'm not sure.
For more complete answers. I would split these up into longer questions, but search SO more completely, as I think most of these have been asked before.