Tag: 资源

rails map.resources with has_many:through不起作用?

我有三个(相关)模型,指定如下: class User :posts, :source => :comments end class Post < ActiveRecord::Base belongs_to :user has_many :comments end class Comment < ActiveRecord::Base belongs_to :user belongs_to :post end 我希望能够引用具有路由的user所有comments_received – 让我们说它是批量批准所有post的评论。 (请注意,您也可以获得用户发表的评论,但用户无法对自己的post发表评论,因此通过post发表的comments不同且相互排斥) 。 从逻辑上讲,这应该适用于: map.resources :users, :has_many => [:posts, :comments, :comments_received] 这应该给我路线 user_posts_path user_comments_path user_comments_received_path 前两个工作,最后一个不工作。 我试过没有_在comments_received无济于事。 我想找一个像这样的url http://some_domain.com/users/123/comments_received 我也试过嵌套它,但也许我做错了。 在那种情况下,我认为地图将是: map.resources :users do |user| user.resources :comments […]

rails资源路由中的默认段名称

我想在我的rails应用程序中创建一条路线 /panda/blog /tiger/blog /dog/blog pandas,老虎和狗都是永久性的(动物类) 这样做的正常方式 map.resources :animals do |animal| animal.resource :blog end 会沿着线路创建路线 /animals/panda/blog /animals/tiger/blog /animals/dog/blog 但我不想要第一段,因为它总是一样的。 我知道我可以通过手动路由来做到这一点,但我想知道如何使用rails资源,因为有动物和博客是我的要求。

同一资源的两个页面–ActiveAdmin

目前我有User模型,它在user.rb注册为ActiveAdmin的新资源。 生成的页面显示具有范围的所有用户( all / journalists / startup_employees )。 现在我想为同一资源和相同的范围创建另一个页面,但是应该只有waiting字段设置为true记录(并且前一页应该仅显示以下内容:waiting => false )。 我怎么能这样做? 我知道我可以用filter做到这一点,但我需要两个单独的页面,菜单中有两个链接。 //解决方案 它比建议更容易(谢谢你们!): ActiveAdmin.register User, :as => ‘Waitlist User’ do menu :label => “Waitlist” controller do def scoped_collection User.where(:waitlist => true) end end # code scope :all scope :journalists scope :startup_employees end ActiveAdmin.register User do controller do def scoped_collection User.where(:waitlist => false) […]

在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不起作用?

Rails路由 – 资源的自定义路由

我正在构建一个Rails应用程序,我想坚持所有那些花哨的东西,如REST和资源,但我想稍微自定义我的路线。 我希望我的GET路线更加冗长 – 我正在创建的应用程序是一个简单的博客,所以我不喜欢GET /posts/1-my-first-post而是喜欢GET /posts/1-my-first-post 。 任何想法如何做到这一点? 没有在网上找到任何东西。