1
我正在嘗試更新我的攝影師模型。但是,如何解決Rails路由和回形針問題不會取代圖像。Rails如何更新圖像?以及如何進行RESTful路由?
當我提交我的表單的網址是:http://localhost:3000/admin/photographers/save.75
這給出了一個錯誤。 Couldn't find Photographer without an ID
而且我的圖像沒有更新。
我的形式:
<%= simple_form_for @photographer, :url => save_admin_photographers_path(@photographer), :html => {:multipart => true, :method => :post} do |f| %>
<%= javascript_include_tag "tiny_mce/tiny_mce" %>
<%= javascript_include_tag "init_my_tiny_mce" %>
<%= f.input :name, :label => 'Name' %>
<%= f.text_area :text, :label => 'Text', :size => '12x12' %>
<%= f.file_field :image, :label => 'Image' %>
<% if @photographer %>
<% if @photographer.image %>
<p class="ok">
<label for="dd">image ok</label>
<%= image_tag("http://s3-eu-west-1.amazonaws.com/kjacobsen/photographer/image/#{@photographer.id}/#{@photographer["image"]}", :size => "39x22") %>
</p>
<p>
<label for="sdd"> </label>
<%= link_to("remove", {:action => "remove_image", :id => @photographer.id}, {:confirm => "Are your sure?"}) %>
</p>
<% else %>
<p class="current">
<label for="dd"></label>
No image uploaded for movie
</p>
<% end %>
<br />
<% end %>
<br />
<%= f.file_field :flv, :label => 'Upload FLV' %>
<br />
<% if @photographer %>
<% if @photographer.flv %>
<p class="ok">
<label for="dd">flv: <%= @photographer["flv"] %></label>
<%= link_to("remove", {:action => "remove_flv", :id => @photographer.id}, {:confirm => "Are your sure?"}) %>
</p>
<% else %>
<p class="current">
No flv uploaded
<br /><br />
</p>
<% end %>
<% end %>
<br />
<%= f.file_field :quicktime, :label => 'Upload Quicktime' %>
<br />
<% if @photographer %>
<% if @photographer.quicktime %>
<p class="ok">
<label for="dd">quicktime: <%= @photographer["quicktime"] %></label>
<%= link_to("remove", {:action => "remove_quicktime", :id => @photographer.id}, {:confirm => "Are your sure?"}) %>
</p>
<% else %>
<p class="current">
<label for="dd"></label>
No quicktime uploaded
<br />
</p>
<% end %>
<% end %>
<%= f.button :submit, :value => 'Create movie' %>
<% end %>
我的更新控制器:
def save
@photographer = Photographer.find(params[:id])
@photographer.update_attributes(params[:photographer])
if [email protected]
flash[:notice] = " "
render_action 'edit'
else
flash[:notice] = "update ok"
redirect_to :action => 'edit', :id => @photographer.id
end
end
我的路線:
namespace :admin do
resources :photographers do
collection do
post :save
end
end
end
我試過了,但在提交表單時得到以下內容:沒有路由匹配「/ admin/photographers/75」 –
@Railsbeginner'rake routes'說什麼?我也假設你的控制器名稱是'Admin :: PhotographersController'? –
我的耙路線:http://pastie.org/2584598 –