use*_*745 2 ruby-on-rails ruby-on-rails-6
当我尝试url_for在 Rails 控制台中使用时,我看到:
url_for(User.first.images.first)
NoMethodError: undefined method `url_for' for main:Object
Run Code Online (Sandbox Code Playgroud)
如何在 Rails 控制台中使用该方法?
您可以使用以下命令在控制台中检查路由帮助程序方法。
app.url_for(User.first.images.first)
该应用程序将为您提供视图上下文。但如果您在应用程序中使用它,请注意。