Tag: 路由

没有路由匹配service-worker.js

我生成了rails应用程序,我收到了这个消息。 我不知道service-worker.js是什么,但我认为它可以捆绑一些默认的gem? Started GET “/service-worker.js” for 127.0.0.1 at 2015-07-21 19:48:33 +0200 ActionController::RoutingError (No route matches [GET] “/service-worker.js”): actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call’ web-console (2.2.1) lib/web_console/middleware.rb:39:in `call’ actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call’ railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app’ railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call’ activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged’ activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged’ activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged’ railties (4.2.3) […]

在rails 4.0中发出问题,为删除操作创建link_to

这是我在rails中的第一个项目,即创建一个存储游戏数据的表。 我能够从表格中显示关于赢家得分,输家得分等的数据。但是,我的表格列中存在包含每个游戏的删除链接的问题。 这是我在删除方法的游戏控制器中的代码: def delete @game = Game.find(params[:game]) @game.destroy() redirect_to :action => ‘index’ end 我的表代码片段,其中包含link_to命令的行 在我调用的路由文件中 resources :games 据我所知,这有助于生成基本路由。 任何人都可以帮我弄清楚为什么我的link_to不起作用?

如何将路线映射到Sinatra的控制器?

我想使用Sinatra创建一个简单的实验性MVC框架。 我想按名称”pages”定义资源,例如应该解析为: /pages (index) /pages/new /pages/:id/show (show) 如同映射到app/controllers/PagesController.rb ,相应的get(‘/’)负责索引, post(‘/pages/create’)负责创建等。 在阅读官方文档之后,我甚至感到非常困惑。 我想我需要使用非经典的Sinatra模型,但有人能指出我正确的方向吗? 谢谢

Rails路由 – 如何将范围参数添加到url_for帮助程序?

我有资源生物和视图和链接添加新生物是: = link_to “Add new bio”, [:new, :admin, :bio] 如果我把资源:生物放到像这样的范围: namespace :admin do scope “/:bio_type”, :defaults => {:bio_type => “company”} do resources :bios end end 这不起作用 = link_to “Add new bio”, [:new, :admin, :bio, { bio_type: params[:bio_type] }] 我的问题是如何在url_for帮助器中添加作用域参数? 并且rails可以默认执行此操作吗? ps new_admin_bio_path({bio_type:params [:bio_type]})工作正常,但它只是好奇

路由机架问题

我正在使用Ruby on Rails 3,我想将一些URL路由到一些Rack中间件。 也就是说,如果用户尝试浏览http://.com/api/user/1 ,系统应考虑在Rack文件之前运行,然后继续执行请求。 我有一个Rack :: Api:用户位于lib/rack/api/user文件夹中。 从RoR官方文档中我发现了这个: Mount a Rack-based application to be used within the application. mount SomeRackApp, :at => “some_route” Alternatively: mount(SomeRackApp => “some_route”) All mounted applications come with routing helpers to access them. These are named after the class specified, so for the above example the helper is either […]

如何生成适当的`url_for`嵌套资源?

我正在使用Ruby on Rails 3.2.2,我想为嵌套资源生成一个正确的url_for URL。 也就是说,我有: # config/routes.rb resources :articles do resources :user_associations end # app/models/article.rb class Article < ActiveRecord::Base … end # app/models/articles/user_association.rb class Articles::UserAssociation < ActiveRecord::Base … end 注意 :生成的命名路由类似于article_user_associations , article_user_association , edit_article_user_association ,… 在我看来,我使用: url_for([@article, @article_association]) 然后我收到以下错误: NoMethodError undefined method `article_articles_user_association_path’ for #<# 但是,如果我以这种方式说明路由器 # config/routes.rb resources :articles do resources :user_associations, […]

Rails 4 – Bootstrap模态forms – 设置

我正在尝试按照本教程在我的Rails 4应用程序中设置包含嵌套表单的模式。 我有Project和Invite的模型。 协会是: Project has_many :invites Invite belongs_to :project 在我的views项目文件夹中,我做了一个名为new_invitation.html.erb的部分 × Modal header **here comes whatever you want to show!** Close Save changes 我正在尝试从我的项目显示页面链接到该项目,该页面包含: true, ‘data-toggle’ => “modal”, ‘data-target’ => ‘#modal-window’} %> 在我的app / javascripts文件夹中,我有一个名为new_invitation.js.erb的文件,其中包含: $(“#modal-window”).html(“”); 在我的应用程序js中,我有: //= require bootstrap/modal (与教程略有不同,因为我使用rails 4和bootstrap sass)。 在我的项目控制器中,我有: def new_invitation respond_to do |format| format.html format.js end end 我将路由从put更改为get动作(虽然我不明白这一步): […]

Rails路由:嵌套,成员,集合,命名空间,范​​围和可自定义

我想了解更多有关Rails路由的信息。 会员和collections # Example resource route with options: resources :products do member do get ‘short’ post ‘toggle’ end collection do get ‘sold’ end end 命名空间和范围 # Example resource route within a namespace: namespace :admin do resources :products end scope :admin do resources :products end 约束,Redirect_to # Example resource route with options: get “/questions”, to: redirect […]

实现单表inheritance后损坏的Rails路由

我已经为person类实现了单表inheritance class Person < ActiveRecord::Base end class Teacher < Person end class Student < Person end class Outsider < Person end 创建人员似乎根据form.select中选择的内容创建了Teacher,Student或Person,并添加了type属性。 但是,我似乎打破了路线 | 它们似乎指向teacher_path,student_path和outsider_path而不是person_path。 路线需要做哪些改变?

Rails 3.1 has_one嵌套资源:路由不生成“所有”路径

我有一个has_one关系: # supplier.rb has_one :presentation … # presentation.rb belongs_to :supplier … 以及它们的以下嵌套路由: # routes.rb resources :suppliers do resource :presentation end 运行rake routes给出: supplier_presentation POST … {:action=>”create”, :controller=>”presentations”} new_supplier_presentation GET … {:action=>”new”, :controller=>”presentations”} edit_supplier_presentation GET … {:action=>”edit”, :controller=>”presentations”} GET … {:action=>”show”, :controller=>”presentations”} PUT … {:action=>”update”, :controller=>”presentations”} DELETE … {:action=>”destroy”, :controller=>”presentations”} 为什么show_helper没有show动作? 我可以覆盖问题,例如: resources :suppliers do resource […]