草庐IT

url.action

全部标签

ruby-on-rails - rake 路由错误 "Missing :action key on routes definition"

我得到了$rakeroutesrakeaborted!ArgumentError:Missing:actionkeyonroutesdefinition,pleasecheckyourroutes./usr/local/rvm/gems/ruby-2.1.2/gems/actionpack-4.1.5/lib/action_dispatch/routing/mapper.rb:243:in`default_controller_and_action'/usr/local/rvm/gems/ruby-2.1.2/gems/actionpack-4.1.5/lib/action_dispa

ruby-on-rails - Rails 点而不是 URL 中的斜线

在我的routes.rb我有:get"projects/:category_id"=>"projects#index"当我编写projects_path(1)时,生成的URL是/projects.1而不是/projects/1。你知道为什么会这样吗?这是rakeroutes的输出:GET/projects/:category_id(.:format)projects#index 最佳答案 projects_path是索引,它只接受一个参数:格式。你想要project_path(1) 关于

ruby-on-rails - Rails 3 中图像路径的完整 url

我有一张图片,其中包含载波上传:Image.find(:first).image.url#=>"/uploads/image/4d90/display_foo.jpg"在我看来,我想为此找到绝对url。附加root_url导致双/。root_url+image.url#=>http://localhost:3000//uploads/image/4d90/display_foo.jpg我不能使用url_for(据我所知),因为要么允许传递路径,或选项列表以标识资源和:only_path选项.因为我没有可以通过“controller”+“action”识别的资源,所以我不能使用:only

ruby-on-rails - 您将如何解析 Ruby 中的 url 以获取主域?

我希望能够使用Ruby解析任何URL以获取没有www的域的主要部分(只是example.com) 最佳答案 请注意没有算法方法可以找到可以为特定顶级域注册域的最高级别(每个注册管理机构的政策不同),唯一的方法是创建所有顶级域的列表以及域可以注册的级别。这就是为什么PublicSuffixList存在。我是PublicSuffix的作者,一个将域分解为不同部分的Ruby库。举个例子require'uri/http'uri=URI.parse("http://toolbar.google.com")domain=PublicSuffix

ruby-on-rails - rails : URL/path with parameters

我想生成一个URL作为/swimming/students/get_times/2013-01-01/2013-02-02从这条路线get_class_swimming_studentsGET/swimming/students/get_times/:start_date/:end_date(.:format)swimming/students#get_times如何将参数传递给get_class_swimming_students_path? 最佳答案 get_class_swimming_students_path('2013-

ruby - 从 href html 标签中使用 ruby​​ 中的 nokogiri 提取链接(URL)?

我想从网页中提取所有URL,如何使用nokogiri做到这一点?例子:site1site2site3resultshouldbeanlist:l=['http://example.org/site/1/','http://example.org/site/2/','http://example.org/site/3/' 最佳答案 你可以这样做:doc=Nokogiri::HTML.parse(site1site2site3site4site5site6HTML_ENDl=doc.css('div.heata').map{|link|

ruby-on-rails - Errno::ECONNREFUSED:连接被拒绝 - connect(2) for action mailer

我长期以来一直在使用Rails。现在我在ActionMailer中遇到了一个小问题。我想在用户注册时发送一封电子邮件以确认他的注册。我可以在开发模式下发送电子邮件,但在生产模式下不能。异常Errno::ECONNREFUSED:Connectionrefused-connect(2)每次调用deliver方法时都会出现。我写了下面的代码。我的SMTP配置如下:config.action_mailer.default_url_options={:host=>"localhost:3000"}config.action_mailer.delivery_method=:smtpconfig.

ruby-on-rails - 如何设置 ActionMailer default_url_options 的 :host dynamically to the request's hostname?

我正在尝试设置:hostforactionmailer默认url选项。我在所有环境文件中设置了以下内容config.action_mailer.default_url_options={:host=>"localhost"}我想通过提供请求主机使其更具动态性。当我尝试通过设置它时config.action_mailer.default_url_options={:host=>request.domain}或config.action_mailer.default_url_options={:host=>request.env["SERVER_NAME"]}它抛出错误...无法识别“请求

ruby - 在 Ruby 中从 URL 获取文件名的好方法是什么?

从以下位置提取filename.jpg的好方法是什么:url='http://www.example.com/foo/bar/filename.jpg?2384973948743'我正在使用Ruby1.9.3。 最佳答案 require'uri'url='http://www.example.com/foo/bar/filename.jpg?2384973948743'uri=URI.parse(url)putsFile.basename(uri.path)#=>filename.jpg

ruby - Action Controller ::未知格式

在我的Rails应用程序中,我向服务器发出了一个ajax请求,以存储一些数据。这曾经没有任何问题,但现在我得到一个错误:ActionController::UnknownFormat(ActionController::UnknownFormat):app/controllers/reservations_controller.rb:45:in`create'如下是Controller和我声明数据类型为JSON的javascript文件classReservationController函数.js$.ajax({url:url_link,dataType:'json',type:'PO