다음은 특종입니다. 사용자가 아이디어를 만든 다음이 아이디어에 거품을 추가 할 수있는 테스트 앱을 만들었습니다. 현재 버블은 텍스트 일뿐입니다. 저는 거품을 아이디어에 성공적으로 연결 시켰습니다. 또한 사용자가 아이디어를 보러 간다면 아이디어에 첨부 된 모든 거품이 나열됩니다. 사용자는 주어진 아이디어에 대한 버블을 삭제할 수도 있습니다.편집 할 때 경로가 일치하지 않습니다.
내 문제는 거품 편집에 있습니다. 사용자가 아이디어를 볼 때 아이디어의 내용과 거품을 볼 수 있습니다. 결과적으로 아이디어 "보기"보기에서 모든 거품 컨트롤 (편집 및 삭제)을 설정했습니다. 거품을 아이디어로 편집하는 코드는 <%= link_to 'Edit Bubble', edit_idea_bubble_path %>
입니다. rake routes
을 실행하여 거품 편집을위한 올바른 경로를 찾았습니다. 그 내용은 나열된 것입니다. 여기
No route matches {:action=>"edit", :controller=>"bubbles"}
내가 가진 :
def edit
@idea = Idea.find(params[:idea_id])
@bubble = @idea.bubbles.find(params[:id])
end
def update
@idea = Idea.find(params[:idea_id])
@bubble = @idea.bubbles.find(params[:id])
respond_to do |format|
if @bubble.update_attributes(params[:bubble])
format.html { redirect_to(@bubble,
:notice => 'Bubble was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "Edit" }
format.xml { render :xml => @bubble.errors,
:status => :unprocessable_entity }
end
end
end
더 단계를 이동하려면, 나는
resources :ideas do
resources :bubbles
end
지금까지 내 routes.rb
파일에 다음 한 버블을 편집하려고 할 때를 제외하고 모든 기능이 작동하는 것 같습니다.
나는 약간의 지침을 원합니다.
감사합니다.
가 여기에 아이디어를 내 show.html.erb
파일입니다 :
<%= render 'form' %>
<%= link_to 'Back to Ideas', ideas_path %>
그리고 마지막으로, 거품 내 _form.html.erb
파일 :이 문제는
<h2>Bubbles</h2>
<% @idea.bubbles.each do |bubble| %>
<p>
<b>Bubble:</b>
<%= bubble.description %>
</p>
<p>
<%= link_to 'Edit Bubble', edit_idea_bubble_path (@idea) %>
</p>
<tb />
<p>
<%= link_to 'Delete Bubble', [bubble.idea, bubble],
:confirm => 'Are you sure you want to delete this bubble?',
:method => :delete %>
</p>
<% end %>
<h2>Add a bubble:</h2>
<%= form_for([@idea, @idea.bubbles.build]) do |f| %>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<div class="actions">
<%= f.submit %> </div><% end %>
edit_idea_bubble_path (@idea)
에 따라, 여기 거품에 대한 edit.html.erb
파일입니다 거짓말, 나는 믿는다.
<% form_for([@idea, @idea.bubbles.build]) do |f| %>
<%= f.error_messages %>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
감사합니다, 나는 ID = 5 버블 찾을 수 없습니다 '다음과 같은 오류가 [("거품"을 .idea_id = 5)] '. '@ idea'를'edit_idea_bubble_path'에서 객체로 사용하면 idea_id (5)를 반환하고, 거품을 편집하는 것과 올바르게 연결되지 않습니다. (나는 편집을 연결하여 bubble_id를 맞출 수 없습니다.) 어떤 제안? – mmichael
또한'@ idea, @ bubble'을'edit_idea_bubble_path' 안에 넣으면 또 다른 오류가 발생했습니다. 따라서'@ idea'를 넣으려고했습니다. '@ 버블 '도 작동하지 않았다. – mmichael
결국 작동 했습니까? – khelll