Tag: nested resources

Rails 4 x paper_trail:使用嵌套资源按item_id过滤版本

在我的Rails 4应用程序中,我有以下模型: class User < ActiveRecord::Base has_many :administrations, dependent: :destroy has_many :calendars, through: :administrations end class Administration < ActiveRecord::Base belongs_to :user belongs_to :calendar end class Calendar < ActiveRecord::Base has_many :administrations, dependent: :destroy has_many :users, through: :administrations end class Post < ActiveRecord::Base belongs_to :calendar end 我安装了paper_trail gem来跟踪我的post模型的变化,如文档中所述 ,它就像一个魅力。 版本显示在Calendars#Index视图中,该视图用作user的仪表板。 以下是我的CalendarsController的设置方法: def index @user = current_user @calendars […]

我无法使用accepts_nested_attributes_for创建模型对象。 它不会创建嵌套对象

我的模型结构如下所示: 董事会has_many主题。 主题has_manypost。 应用程序/模型/ board.rb class Board < ActiveRecord::Base has_many :topics end 应用程序/模型/ topic.rb class Topic < ActiveRecord::Base belongs_to :user belongs_to :board has_many :posts accepts_nested_attributes_for :posts validates :title, presence: true, length: { maximum: 255 } validates :user_id, presence: true validates :board_id, presence: true … end 应用程序/模型/ post.rb class Post < ActiveRecord::Base belongs_to :user belongs_to :topic […]

如何将PGSeaerch结果链接到嵌套资源中的索引页面?

我终于想出了如何实现pg_search的multiisearchfunction。 但是我在制作一个可用的搜索页面时遇到了麻烦,该页面显示了返回相应嵌套页面的链接。 如何传递正确的ID,以便链接到嵌套视图。 所以类似于link_to myapp.com/artists/1/albums 到目前为止,我得到了这个错误(我似乎无法通过艺术家ID) No route matches {:controller=>”albums”, :artists=>nil} Rails的新手请帮忙:) CONTROLLERS class ResultsController params[:page] ) @artists = PgSearch.multisearch(params[:query]).where(searchable_type: “Artist”) @albums = PgSearch.multisearch(params[:query]).where(searchable_type: “Album”) end end VIEWS Artists #### How can I link to the Albums index page Albums ####How can I link to the Albums index page 楷模 class Artist :albums include PgSearch […]