1、当前Rails的版本号是多少?
由于 Rails 版本会不断更新,当前版本号处于动态变化中,仅给出固定的 5.0.0 无法准确对应当前版本,所以答案为 DELETE 。
2、在一个Ruby的控制器代码中,将 hello 动作的内容改为“hola, mundo!”,而不是“hello, world!”。
需要对代码进行修改,将 render html: "hello, world!" 替换为 render html: "hola, mundo!" ,修改后的代码如下:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def hello
render html: "hola, mundo!"
end
end
3、通过包含倒感叹号(如 “¡Hola, mundo!”)来证明 Rails 支持非 ASCII 字符。
在代码中将内容修改为包含倒感叹号的 ¡Hola, mundo! ,在 Mac 上可使用 Option + 1 输入 ¡ 字符,其他情况可复制粘贴该字符到编辑器。编辑器可能显示 "invalid multibyte character" 消息,但无需担心,若想消除该消息可在谷歌搜索错误信息。
4、在 Rails 应用中,添加一个名为 goodbye 的动作,使其渲染文本“goodbye, world!”。并编辑路由文件,使根路由指向 goodbye 动作。
首先,在 app/controllers/application_controller.rb 文件中添加 goodbye 动作:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def hello
render html: "hello, world!"
end
def goodbye
render html: "goodbye, world!"
end
end
然后,编辑 config/routes.rb 文件,将根路由指向 goodbye 动作:
Rails.application.routes.draw do
root 'application#goodbye'
end
5、运行heroku help查看Heroku命令列表,显示应用日志的命令是什么?
heroku logs
6、用户编辑页面的视图文件名称是什么?
app/views/users/edit.html.erb
7、尝试创建一个内容超过140个字符的微型帖子(例如,可参考维基百科上关于Ruby的文章的第一段来创作)。
可在新的微型帖子页面输入超过140个字符的内容来创建,若按代码约束,Rails 会渲染错误消息,提示微型帖子的内容过长。
8、在生产应用程序上创建几个用户
首先,将Faker gem添加到Gemfile中,如下所示:
```ruby
source 'https://rubygems.org'
gem 'rails', '5.0.0'
gem 'bcrypt', '3.1.11'
gem 'faker', '1.6.3'
然后执行:
$ bundle install
接着,在标准文件 db/seeds.rb 中添加 Ruby 程序来为数据库填充示例用户,代码如下:
User.create!(
name: "Example User",
email: "example@railstutorial.org",
password: "foobar",
password_confirmation: "foobar"
)
99.times do |n|
name = Faker::Name.name
email = "example-#{n+1}@railstutorial.org"
password = "password"
User.create!(
name: name,
email: email,
password: password
)
end
##9、通过尝试创建一个内容超过140个字符的微博,确认对微博内容长度的验证在生产应用中是否有效。
可以前往新微博页面,输入超过140个字符的内容。若渲染出错误消息,表明微博内容过长,那么就可以确认对微博内容长度的验证在生产应用中有效。
##10、通过访问生产服务器上的根路由,验证向 Heroku 的部署是否成功。
要验证向 Heroku 的部署是否成功,可访问运行 `heroku create` 时看到的地址。若在本地机器而非云 IDE 上操作,也可使用 `heroku open` 命令。若页面能正常显示,则表明部署成功。
##11、销毁Foo控制器及其关联操作。
可以使用命令 `rails destroy controller Foo` 来销毁 Foo 控制器及其关联操作。
##12、在静态页面控制器测试中存在一些重复,特别是基础标题 “Ru

最低0.47元/天 解锁文章
12

被折叠的 条评论
为什么被折叠?



