以下是獨家新聞:我創建了一個測試應用程序,允許用戶創建想法,然後爲這些想法添加「泡泡」。目前,泡沫只是文字。我已經成功地將泡沫與想法聯繫起來此外,當用戶去查看一個想法時,它會列出所有附在該想法上的氣泡。用戶甚至可以刪除給定想法的泡泡。嘗試編輯時沒有路線匹配
我的問題在於編輯氣泡。當用戶看到一個想法時,他會看到該想法的內容以及該想法的任何泡沫。因此,我已將所有的氣泡控件(編輯和刪除)設置在想法「展示」視圖中。我編輯泡泡的主意是<%= 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
爲了進一步走了一步,我有我的routes.rb
文件下列
resources :ideas do
resources :bubbles
end
到目前爲止除非我嘗試編輯泡泡,否則一切似乎都起作用。
我想要一些指導。
謝謝!
這是我show.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
文件氣泡:
<%= render 'form' %>
<%= link_to 'Back to Ideas', ideas_path %>
最後,我_form.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泡泡[WHERE(「泡沫」 .idea_id = 5)] `。在`edit_idea_bubble_path`中使用'@ idea`作爲對象返回了idea_id(5),並且沒有正確地鏈接到編輯泡泡(我似乎無法鏈接編輯來觸發bubble_id)。有什麼建議麼? – mmichael 2011-02-07 01:28:00