草庐IT

save_path

全部标签

ruby-on-rails - 如何在 Rails 中覆盖 `root_path`?

我有这样定义的语言环境:#routes.rbscope"(:locale)",locale:/#{I18n.available_locales.join("|")}/do...root"home#index"end我还在ApplicationController的default_url_params中设置了语言环境。这样我的所有路线和网址都包含这样的语言环境:http://example.com/en/somethinghttp://example.com/fr/something这对我来说是预期的行为。我也有这样的根网址:http://example.com/enhttp://exa

ruby-on-rails - 使用 heroku rails 时出错,找不到数据库客户端 psql。检查您的 $PATH 并重试

尝试执行需要我执行railsdb的数据库操作我正在执行herokurunrailsdb但我得到了Runningrailsdbattachedtoterminal...启动,运行.7334找不到数据库客户端:psql。检查您的$PATH并重试。我做了:gemupdateheroku但是没有用。仍然出现相同的错误。还有:$herokurunbundleexecrailsdb--accountwork--appdmplanningRunning`bundleexecrailsdb`attachedtoterminal...up,run.1572Couldn'tfinddatabaseclie

ruby-on-rails - Rails 3.2.13 recognize_path 返回约束的路由错误

我的路由中有两条路径,同一条路径指向不同的Controller和Actionmatch'/:id'=>'users#show',:as=>'user',:constraints=>UserConstraintmatch'/:id'=>'customers#show',:as=>'customer'我的约束类有以下匹配项吗?方法defself.matches?(request)returnUser.exists?(request.path_parameters[:id])end当我在我的浏览器中调用url时,这工作正常。但是,这不适用于recognize_path方法。Rails.app

ruby-on-rails - 教程 Michael Hartl 在 9.3 上访问 edit_user_path 失败

我有一个我无法解决的错误。我按照教程中的步骤操作,但无法通过绿色测试。我遇到了这个错误:$bundleexecrspecspec/requests/user_pages_spec.rb-e"Editpage"Runoptions:include{:full_description=>/Edit\page/}FFFFailures:1)UserpagesEditpageFailure/Error:before{visitedit_user_path(user)}ActionView::Template::Error:undefinedmethod`model_name'forNilCla

ruby-on-rails - articles_path 是如何工作的? (RubyOnRails 教程)

我正在关注theofficialrubyonrailstutorial我刚刚完成了第5.9章。添加链接应该很简单,但我很困惑。当我输入bin/rakeroutes时,我得到以下输出:fl4m3ph03n1x:~/blog$bin/rakeroutesPrefixVerbURIPatternController#ActionarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/articles/new(.:format)articles#newedi

ruby-on-rails - rails : How do I cancel a save if before_update callback returns false?

我有一个模型,它有一个before_update回调。根据我的理解,当在模型实例上调用update_attributes时,将调用before_update。我的假设是,如果before_update回调返回false,则不会更新记录。然而,这似乎并没有像假设的那样工作。每次我调用update_attributes时,即使before_update返回false,记录也会被保存。如果before_update返回false,您知道如何防止更新记录吗?这是我在user.rb文件中尝试过的内容:classUsertruebefore_updatedofalseendend这是我在Rails

ruby-on-rails - Rails 正在向后路由我的 calendar_event_path 吗?

Rails给我的URL的ID顺序错误。它将父ID传递给子代,将子ID传递给父代。在我的routes.rb中有resources:calendarsdoresources:eventsend哪个rakeroutes告诉我正在设置好的路线,例如calendar_eventGET/calendars/:calendar_id/events/:id(.:format){:controller=>"events",:action=>"show"}所以当我从我的部分View中请求该路线的路径时,它给了我一个id颠倒的url...http://localhost:3000/calendars//ev

ruby - LoadError : Expected {app_path}/models/model file. rb 定义模型名称

运行时出现错误LoadError:Expected/home/user/Desktop/Tripurari/myapp/app/models/host.rbtodefineHost##但它上面的每样东西都各就各位。有人能告诉我方法下面的确切问题是什么吗?defself.check_all(keyword)memo_mutex=Mutex.newmemo={}threads=[]name=keyword.keywordSITES.eachdo|site_and_options|threads 最佳答案 问题可能是由自动加载器引起的。如

ruby-on-rails - 为什么 `posts_path` 在 `rails console` 中不起作用?

为什么link_to'Back',posts_path在ERB中有效,但posts_path在控制台中无效?$railsconsoleirb(main):005:0>posts_pathNameError:undefinedlocalvariableormethod`posts_path'formain:Object 最佳答案 您需要在控制台中添加应用的上下文。app.posts_pathapp.getapp.posts_pathapp.responseapp.response.body

ruby-on-rails - before_save 如果 attribute.present?

before_save:date_started_sets_deadline,ifdate_started.present?如果:date_started==nil,我不希望此before_save运行。我已经尝试了上述行的各种版本,所以不确定是否必须更改它或方法本身。defdate_started_sets_deadlineifself.date_started>Date.tomorrowself.deadline=self.date_startedendend我试图避免错误NoMethodError(undefinedmethod'>'fornil:NilClass):app/mo