Tag: ruby on rail

Rails嵌套路由的奇异​​资源

我在单一资源上有一个嵌套路由 map.resource :account, :controller => “users” do |page| page.resources :feeds end 我正在尝试制作一个表单来添加Feed。 我从这开始…… undefined method `feeds_path’ for # 所以我试试 undefined method `user_feeds_path’ for # 我想这是因为将它从“用户”重命名为“帐户”? 所以我试过了 `@/account/feeds.%23%3Cfeed:0x22ea5c0%3E’ is not allowed as an instance variable name 不确定那个错误意味着什么。 所以我已经使用了这样做: {:action=>:create} do |f| %> 这真的是最好的方式吗? 换句话说,在这种情况下是否无法使用命名路由?

Rails&Devise:设计未在rails控制台中显示的特定列

我试图在我的用户模型上使用Devise,但是当我进入rails控制台并尝试User.new我只得到: irb(main):002:0> User.new => # 为什么设计列没有出现? CreateUsers迁移: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :first_name t.string :last_name t.string :email t.timestamps null: false end end end AddDeviseToUsers迁移: class AddDeviseToUsers < ActiveRecord::Migration def self.up change_table :users do |t| ## Database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" […]

条纹“提供的API密钥无效”

我完全按照Stripe的Rails教程( https://stripe.com/docs/checkout/guides/rails )(复制和粘贴代码),但是当我运行rails时 PUBLISHABLE_KEY=pk_foo SECRET_KEY=sk_bar rails s 并转到localhost:3000 / charge / new并填写带有测试卡数据的字段(卡号“4242 4242 4242 4242”),但我得到了 Invalid API Key provided: ***********_*** 任何想法为什么会这样?

rails设计edit_user_password_path

我无法路由到项目的edit_user_password_path。 它只是路线到家。 有人可以帮忙吗?

如何路由用户配置文件URL以跳过控制器?

现在我的用户个人资料url如下: http://example.com/users/joeschmoe 这指向用户控制器中的show方法。 我理想的做法是提供如下用户个人资料url: http://example.com/joeschmoe 那么,什么样的路线和控制器魔法需要发生才能解决这个问题?

Ruby on rails应用程序root

如何更改rails应用程序以使控制器foo显示为应用程序根目录? 换句话说,现在所有的url看起来像host.com/foo / …我想摆脱foo,只需要host.com / …

formtastic中date_helper的默认值

听起来很基本,我不能将date_helper默认为日期,如: – semantic_form_for resource do |f| – f.inputs do = f.input :issued_on, :default => Date.today = f.buttons 如果资源没有日期,上面只会呈现空白列。 希望任何关于我可能做错的指针。

Rails在测试失败时最小的崩溃

当我运行rails test (Rails 5和Ruby 2.4.2)时,每次测试失败时Minitest都会崩溃。 例如,我通过将assert切换为assert_not强制简单测试失败: Failure: TransactionTest#test_transaction_should_be_valid [/home/…/test/models/transaction_test.rb:11]: Expected true to be nil or false /home/…/.rvm/gems/ruby-2.4.2/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `method’: undefined method `test_transaction_should_be_valid’ for class `Minitest::Result’ (NameError) 如果测试通过,那么整个报告都会成功,我会收到报告摘要。 如果只有一个测试失败,我会得到上面的错误报告。 我在transaction_test.rb文件中定义了test_transaction_should_be_valid ,certificate它在测试通过时运行顺畅。 我现在坚持这个。 关于可能导致这种情况的任何想法?

没有路线匹配“/ logout”

单击“注销”时出现以下路由错误: No route matches [GET] “/logout” 这是我的application.html.erb文件: :delete %> 这是我的routes.rb文件: get ‘admin’ => ‘admin#index’ controller :sessions do get ‘login’ => :new post ‘login’=> :create delete ‘logout’ => :destroy end get “sessions/create” get “sessions/destroy” 有人知道如何解决这个问题吗?

如何跟踪一个用户在线的时间? 使用Ruby on Rails

我有一个使用Devise的Rails应用程序用于validation用户,但我想在平台上跟踪用户在线的时间 。 我想在用户表中有一个列,可以节省此用户的在线时间(小时,分钟……)。 例如,一个用户总共在线2小时,另一个用户15分钟…… 是否存在一些用于此function的gem或Devise方法? 提前致谢。