首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails Link_to链接到不想要的视图。

Rails Link_to链接到不想要的视图。
EN

Stack Overflow用户
提问于 2013-08-15 21:38:45
回答 1查看 202关注 0票数 0

在我看来,我的link_to将变成一个与我所希望的完全不同的"show.html.erb“。我基本上是想弄清楚为什么"link_to“展览要链接到一个”调查“档案。我认为这可能与我的路线文件有关,或者它是”属于“relationship...but的事实,似乎无法得到它-- workin...what,link_to应该是什么?

更新:(根据BROIS的问题)失态的link_to出现在<%= link_to @ show.html.erb的do %>展览中

我的EXHIBIT.RB (模型)

代码语言:javascript
复制
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

我的展品管理员:

代码语言:javascript
复制
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

我的ROUTES.RB

代码语言:javascript
复制
resources :sessions, only: [:new, :create, :destroy]

resources :investigations do
resources :players
end

resources :investigations do
resources :exhibits
end

最后,我的SHOW.HTML.ERB (调查简介)

代码语言:javascript
复制
<% @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 %>

增加了调查主任

代码语言:javascript
复制
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

增加调查模型

代码语言:javascript
复制
class Investigation < ActiveRecord::Base
  # belongs_to :user

  has_many :players, dependent: :destroy
  has_many :exhibits, dependent: :destroy


  default_scope -> { order('created_at DESC') }
end

我很感谢help...if,我需要发布更多的信息,请告诉我

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-16 01:35:08

在您的:app/contoroller/exhibits_Controller.rb

代码语言:javascript
复制
def show
@investigation = Investigation.find(params[:investigation_id])
@exhibit = Exhibit.find(params[:id])
end

在您的应用程序/视图/展品/show.html.erb

代码语言:javascript
复制
<%= link_to investigation_exhibit_path(@investigation, @exhibit) do %>

也许吧,我想。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18262325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档