[英]update record in rails
我想在我的“Place”模型中添加新圖像。 向控制器添加新方法/操作並從Place show page添加新表單是一種好習慣嗎?
如果沒有那么什么是最佳做法?
在控制器中
def add_images
@place = Place.find(params[:id])
#DO THE CHANGES HERE
@palce.save;
redirect_to places_path
end
在路線上
match 'places/:id/add_images' => 'places#add_images'
在視圖中
<%= form_tag @place.id.to_s+'/add_images', :method => 'post', :multipart => true do %>
<!-- just test -->
<div class="actions">
<%= submit_tag "submit new images" %>
</div>
<% end %>
使用新表單:form_for @place with image file_field,在控制器中使用update action
def update
@place.update_attributes params[:place]
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.