2014-02-09 1 views
0

현재 올바르게 div에 텍스트 링크가 있습니다. <%= link_to 'Show', profile %>. 나는 아래는 내 블록에 그것을 시도하지 않고 나에게 undefined local variable or method 'profile'div에서 링크 만들기 - Ruby on Rails

<%= link_to profile do %> 
    <div id="profiles" class="transitions-enabled"> 
    <% @profiles.each do |profile| %> 
    <div class="box panel panel-default"> 
    <div class="panel-body"> 
    <%= image_tag profile.image.url(:medium) %> 
    <%= profile.artist %><br/> 
    <%= link_to 'Show', profile %> 
    </div> 
    </div> 
    <% end %> 
</div> 
<% end %> 

내 원래 블록을 준다 적용 할 때 링크

<%= link_to root_path do %> 
    <div>Hey!</div> 
<% end %> 

비록로 사업부를 설정하는 적절한 방법이라고 읽고 연결시 :

<div id="profiles" class="transitions-enabled"> 
<% @profiles.each do |profile| %> 
    <div class="box panel panel-default"> 
    <div class="panel-body"> 
    <%= image_tag profile.image.url(:medium) %> 
    <%= profile.artist %><br/> 
    <%= link_to 'Show', profile %> 
    </div> 
    </div> 
<% end %> 
</div> 

내 컨트롤러 :

class ProfilesController < ApplicationController 
    before_action :set_profile, only: [:show, :edit, :update, :destroy, :id] 

# GET /profiles 
# GET /profiles.json 
def index 
    @profiles = Profile.all 
end 

# GET /profiles/1 
# GET /profiles/1.json 
def show 
end 

# GET /profiles/new 
def new 
    @profile = Profile.new 
end 
#... 
+0

- 당신이 질문에가있을거야 넣어 경우 당신이 원하는 것을하기위한 레일 코드를 제공하기는 쉽지만 ... 출력 HTML을 어떻게 보이길 원하나요? 그냥 예를 들어 ... –

+0

@RichardJordan은 그리드가있어서 각 "프로파일"을 클릭 할 수있게하고 싶습니다 - > http://cl.ly/image/3I1F2e3r0f08 – Jadam

+0

당신의 위의 예는 링크 안에 링크가 있습니다 - 그래서 나는 당신이 그것을 나오기를 바라고있는 것에 대해 다소 혼란스러워합니다. 출력 할 기본 html 구조를 보여줄 수 있습니다. 효율적으로 레일스 코드를 사용하면 –

답변

0

첫 번째 예는 여러면에서 문제가 있습니다. 링크 안에 링크가 있습니다. 난 당신이 출력에 무엇을 찾고 있는지 정확히 모르겠어요 -하지만 기본적으로 당신은 당신의 라인을 따라 <%= link_to 'Show', profile %>

뭔가가 어디 대체 할

<%= link_to root_path do %> 
    <div>Hey!</div> 
<% end %> 

행동이 필요합니다

<div id="profiles" class="transitions-enabled"> 
    <% @profiles.each do |profile| %> 
    <div class="box panel panel-default"> 
     <div class="panel-body"> 
     <%= image_tag profile.image.url(:medium) %> 
     <%= profile.artist %><br/> 

     <%= link_to profile do %> 
      <div> 
      fancy pants stuff here 
      </div> 
     <% end %> 

     </div> 
    </div> 
    <% end %> 
</div> 

div에서 원하는 내용에 대한 지침을 제공 할 수 있다면이를 달성 할 수있는 몇 가지 코드를 게시 할 수 있습니다. 정확히 무엇을 찾고 있는지 명확하지 않습니다.

은 내부에 떨어 조각을 더 원하는 경우 또 다른 예는 (할 수있는 <div></div> : html로하면 출력에 노력하고 무엇

<div id="profiles" class="transitions-enabled"> 
    <% @profiles.each do |profile| %> 
    <div class="box panel panel-default"> 
     <div class="panel-body"> 

     <%= link_to profile do %> 
      <div> 
      <%= image_tag profile.image.url(:medium) %> 
      <%= profile.artist %><br/> 
      ... more fancy pants stuff here ... 
      </div> 
     <% end %> 

     </div> 
    </div> 
    <% end %> 
</div>