私のビューのlink_toは、私が望むものとはまったく異なる「show.html.erb」になります。私は基本的に、「link_to @exhibit が「Investigation」プロファイルにリンクしている理由を理解しようとしています。ルート ファイルまたは「所属」関係であるという事実に関係している可能性があると思いますが、できません」動作しているようには見えません...そのlink_toは何ですか?
更新: (AS PER BROIS QUESTION) show.html.erb の <%= link_to @exhibit do %> に行方不明の誤動作した link_to があります
MY EXHIBIT.RB (モデル)
class Exhibit < ActiveRecord::Base
attr_accessible :content, :investigation_id, :name, :user_id, :media, :media_html
belongs_to :investigation
has_many :categorizations
has_many :categories, :through => :categorizations
validates :name, presence: true, length: { maximum: 140 }
validates :content, presence: true
default_scope -> { order('created_at DESC') }
auto_html_for :media do
html_escape
image
youtube(:width => 400, :height => 250)
link :target => "_blank", :rel => "nofollow"
simple_format
end
私の展示コントローラー:
class ExhibitsController < ApplicationController
include AutoHtml
def new
@exhibit = Exhibit.new
end
def show
@exhibit = Exhibit.find(params[:id])
end
def index
@exhibits = Exhibit.paginate(page: params[:page])
end
def create
@investigation = Investigation.find(params[:investigation_id])
@exhibit = @investigation.exhibits.create(params[:exhibit])
if @exhibit.save
flash[:success] = "You've successfully added etc etc..."
redirect_to investigation_path(@investigation)
else
render 'new'
end
end
end
マイルート.RB
resources :sessions, only: [:new, :create, :destroy]
resources :investigations do
resources :players
end
resources :investigations do
resources :exhibits
end
最後に、私の SHOW.HTML.ERB (調査プロファイル)
<% @investigation.exhibits.each do |exhibit| %>
<div class="row-fluid services_circles">
<%= link_to @exhibit do %>
<div class="media">
<div class="pull-left">
<%= exhibit.media_html %>
</div>
<div class="media-body">
<h4 class="media-heading"><%= exhibit.name %></h4>
<p><%= exhibit.content %></p>
</div>
</div>
<% end %>
<% end %>
捜査管制官を追加
class InvestigationsController < ApplicationController
def new
@investigation = Investigation.new
end
def show
@investigation = Investigation.find(params[:id])
end
def index
@investigations = Investigation.paginate(page: params[:page])
end
def create
@investigation = Investigation.new(params[:investigation])
if @investigation.save
flash[:success] = "You've successfully created..."
redirect_to @investigation
else
render 'new'
end
end
end
調査モデルを追加
class Investigation < ActiveRecord::Base
# belongs_to :user
has_many :players, dependent: :destroy
has_many :exhibits, dependent: :destroy
default_scope -> { order('created_at DESC') }
end
助けていただきありがとうございます...さらに情報を投稿する必要がある場合はお知らせください