Rails指南第5.12节中的UrlGenerationError

我正在按照Rails 4.0.0的入门教程进行操作: http : //guides.rubyonrails.org/getting_started.html#updating-posts 当我尝试从主页面(localhost)导航到localhost / posts时,我收到此错误: ActionController::UrlGenerationError in Posts#index Showing C:/RailsInstaller/blog/app/views/posts/index.html.erb where line #16 raised: No route matches {:action=>”show”, :controller=>”posts”} missing required keys: [:id] Extracted source (around line #16): 13 14 15 16 17 18 19 此外,当我尝试编辑post时,我在edit.html.erb文件中收到一个SyntaxError: C:/RailsInstaller/blog/app/views/posts/edit.html.erb:3: syntax error, unexpected ‘}’, expecting keyword_end ‘;@output_buffer.append= form_for :post, url: post_path(@post.id) }, ^ C:/RailsInstaller/blog/app/views/posts/edit.html.erb:32: syntax […]

从嵌套表单发出combobox中的更新类

我创建了一个combobox,显示供应商,因此当选择供应商时将更新显示购买的div,显示购买后将以comboboxforms进行嵌套,因此当我选择购买时将显示所选购买的金额。 问题是,当我选择购买时,仅在第一行中工作,当我选择另一个combobox线时,显示所选择的第一个combobox的数量。 在这里我的表 suppliers |id| |name| 1 Supplier A 2 Supplier B shopping_documents |id| |supplier_id| 1 1 2 2 shopping_products |id| |shopping_document_id| |qty| |purchase_product_id| 1 1 1 1 2 1 1 2 purchase_products |id| |name| |price_sale| 1 XP 1000 2 VISTA 2000 supplier_products |id| |supplier_id| |amount| |purchase_product_id 1 1 1000 1 2 1 2000 1 […]

解析@username的post

我已经建立了类似Twitter的@replies,允许用户通过用户每日邮件相互联系…类似于stackoverflow。 以此为指导https://github.com/kltcalamay/sample_app/compare/original-version…master 如何解析/扫描post,然后将@usernames替换为该用户页面的链接 post的例子。 Kevins Post: @Pzpcreations @john @steve hey everyone lets all hang out today 我想扫描/解析post,然后将用户@Pzpcreations @john @steve链接到他们的个人资料 我尝试在Dailypost模型中创建一个方法,将用户名存储在数组中….但IDK如何替换并将它们链接到相应的用户页面 def username_link str = self.content_html recipient = str.scan(USERNAME_REGEX) end 这给了我[“@Pzpcreations”,“@ john”,“@ step”] 请帮帮我….新到铁路:) 楷模 class Recipient < ActiveRecord::Base attr_accessible :dailypost_id, :user_id belongs_to :user belongs_to :dailypost end class User ‘Recipient’, :dependent => :destroy has_many :received_replies, :through […]

如何根据行中的文本单击表中的链接

使用page-object和watir-webdriver如何根据行文本单击表中的链接,如下所示: 该表包含3行,其中第一列中包含名称,右侧列中包含相应的“详细信息”链接: 仪表板….详情 示例……细节 等等。 ALL THE DETAILS: ….soon DASHBOARD: —> Based on this text ….some element Details —> I should able click this link

最好使用EM.next_tick或EM.defer与Eventmachine进行长时间运行计算?

我试图弄清楚如何在我必须自己实现的长时间运行的计算中使用延迟。 对于我的例子,我想计算前200000个斐波纳契数,但只返回一个。 我对延期的第一次尝试看起来像这样: class FibA include EM::Deferrable def calc m, n fibs = [0,1] i = 0 do_work = proc{ puts “Deferred Thread: #{Thread.current}” if i < m fibs.push(fibs[-1] + fibs[-2]) i += 1 EM.next_tick &do_work else self.succeed fibs[n] end } EM.next_tick &do_work end end EM.run do puts "Main Thread: #{Thread.current}" puts "#{Time.now.to_i}\n" EM.add_periodic_timer(1) do […]

如何声明依赖于参数化任务的Rake任务?

我见过一个例子,其中一个任务有参数和一个依赖任务,如: task :name, [:first_name, :last_name] => [:pre_name] do |t, args| args.with_defaults(:first_name => “John”, :last_name => “Dough”) puts “First name is #{args.first_name}” puts “Last name is #{args.last_name}” end 如果它是一个任务依赖项,你将如何将参数传递给name任务: task :sendLetter => :name #do something end

如何在rails控制台上加载ruby中的文件?

我正在尝试加载一个文件,我将所有设置都放入rails控制台。 我想这样做,因为当我使用控制台时,重复次数过多。 谢谢

array * string在Ruby中意味着什么?

我正在浏览一些Rails源代码并遇到过 # File vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 129 129: def target! 130: @target * ” 131: end *”做什么? 那是乘空字符串……? 你为什么要这样做呢。

Ruby 1.9.2发生了什么?

我已经看到Ruby 1.9.2没有更新。 (仅适用于Ruby 1.9.3和2.0)。 我的问题是:1.9.2发生了什么? 我很困惑,如果1.9.3和1.9.2是不同的分支,或1.9.3是续集,如果我的1.9.2应用程序将与1.9.3没有问题。

ruby数组循环总是对

我有以下数组: a = [‘sda’, ‘sdb’, ‘sdc’, ‘sdd’] 现在我想循环遍历这些条目,但总是有两个元素。 我现在这样做如下: while b = a.shift(2) # b is now [‘sda’, ‘sdb’] or [‘sdc’, ‘sdd’] end 这感觉有点不对,有更好的方法吗? 有没有办法轻易搞定[[‘sda’, ‘sdb’], [‘sdc’, ‘sdd’]] ? 我阅读了http://www.ruby-doc.org/core-1.9.3/Array.html,但我找不到有用的东西……