1
我無法管理使用回形針進行文件上傳。 我下面這個教程回形針文件無法上傳
http://larsgebhardt.de/parse-xml-with-ruby-on-rails-paperclip-and-nokogiri/
這是我做過什麼:
route.rb:
resources :users do
resources :rides do
resources :comments
end
resources :challenges do
get "accept"
post 'accept'
end
end
...
validates :gpx, presence: true
rides.rb:
require 'nokogiri'
class Ride < ActiveRecord::Base
belongs_to :user
has_many :comments, dependent: :destroy
has_many :challenges
# Tracksegments
has_many :tracksegments, :dependent => :destroy
has_many :points, :through => :tracksegments
has_attached_file :gpx
create_rides.rb
add_attachment :rides, :gpx
rides/new.html.erb
<h1>New Ride</h1>
<%= form_for [@user,@ride] do |f| %>
<div>
<%= f.label :name, :class => 'control-label' %>
<div>
<%= f.text_field :name, :class => 'text_field' %>
</div>
</div>
<div>
<%= f.label :gpx, :class => 'control-label' %>
<div>
<%= f.file_field :gpx %>
</div>
</div>
<div>
<%= f.submit %>
</div>
<% end %>
<div>
<%= link_to 'Back', user_rides_path %>
</div>
一切呈現良好,但該文件沒有上傳。由於model.rb中的當前驗證集,頁面被卡住了。哪裏不對?
:在我的控制器中不允許使用gpx –
很高興您能夠正常工作! –