Я пытаюсь выяснить полиморфные отношения, и я продолжаю получать следующие ошибки с моими маршрутами всякий раз, когда я пытаюсь добавить индекс, чтобы показать все + с помощью activeadmin.
Ошибка 1: я пробовал множество различных вариантов для этого, иногда я получаю сообщение об ошибке, иногда нет ошибки, но ничего не появляется.
Ошибка 2: NameError в Admin::Places#index, неинициализированная константа Place::FavoritePlace, insert_tag renderer_for(:index) ---> Для этой ошибки я попытался добавить в remove_filter :favorites (и разные варианты этого), но это решение не сработало.
У меня есть модель, места, которые я хочу, чтобы пользователи могли добавить место в список избранных. Я хотел бы страницу, которая показывает все избранное текущим пользователем. На данный момент пользователь может добавить/удалить место из избранного. Был бы признателен за любую помощь. Спасибо!
place.rb
class Place < ActiveRecord::Base
#Favorites
has_many :favorites
has_many :favorite_places, through: :favorites, source: :favorited, source_type: 'Place'
end
любимый.rb
class Favorite < ActiveRecord::Base
belongs_to :user
belongs_to :favorited, polymorphic: true
belongs_to :place
end
favorite_places_controller.rb
class FavoritePlacesController < ApplicationController
before_action :set_place, except: [:index]
def index
@places = User.favorite_places
end
def create
if Favorite.create(favorited: @place, user: current_user)
redirect_to @place, notice: 'Place has been favorited'
else
redirect_to @place, alert: 'Something went wrong. *womp womp*'
end
end
def destroy
Favorite.where(favorited_id: @place.id, user_id: current_user.id).first.destroy
redirect_to @place, notice: 'Place is no longer a favorite'
end
private
def set_place
@place = Place.find(params[:place_id] || params[:id])
end
end
routes.rb
#favorites
resources :favorite_places
views/favorite_places/index.html.erb
<% @places.each do |place| %>
<div class="box panel panel-default">
<div id="image-wrapper">
<span itemprop="photo"><%= link_to image_tag(place.image.url(:medium)), place, class: "hover" %></span>
<p class="image-text text-center"> <span itemprop="name">
<%= place.name %>
</span>
<br>
<span itemprop="servesCuisine"><%= ["beer", "chocolate" ,"cocktail", "coffee", "tea", "wine", "juice"] [place.kind] %>
</span>
</p>
</div>
</div>
<% end %>
admin/place.rb
ActiveAdmin.register Place do
controller do
def permitted_params
params.permit place: [ :city_id, :description, :image_file_name, :image_content_type, :image_file_size, :name, :kind, :address, :latitude, :longitude, :website, :dress, :food, ":image_updated_at(1i)", ":image_updated_at(2i)", ":image_updated_at(3i)", ":image_updated_at(4i)", ":image_updated_at(5i)" ]
end
end
end
belongs_to :place
вfavorite.rb
? - person Bongs   schedule 01.09.2014