我在BitNami RubyStack下使用Ruby on rails 2.3.2进行编码。当我调用上传控制器时,我得到这样的错误:
compile error
C:/Users/BitNami RubyStack/killerapp/app/views/upload/index.html.erb:6:
unterminated string meets end of file
C:/Users/BitNami RubyStack/killerapp/app/views/upload/index.html.erb:6:
syntax error, unexpected $end, expecting ')'
索引视图的代码:
<% form_for :picture, :html => { :multipart => true } do |form| %>
<label for="first_name">First_Name:</label>
<%= form.text_field :first_name %>
<label for="last_name">Last_Name:</label>
<%= form.text_field :last_name %>
<%= submit_tag "upload" %>
<% end %>
字符串编号6是:
<%= submit_tag "Upload" %>
有什么问题?求你帮帮我。
答案 0 :(得分:0)
尝试
<% form_for :picture, :html => { :multipart => true } do |form| %>
<%= label :picture, :first_name, "First Name" %>
<%= form.text_field :first_name %>
<%= label :picture, :last_name, "Last Name" %>
<%= form.text_field :last_name %>
<%= form.submit "upload" %>
<% end %>
并添加
# routes.rb
map.resources :pictures
答案 1 :(得分:0)
ActionController::Routing::Routes.draw do |map|
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# map.resources :products
# Sample resource route with options:
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
# Sample resource route with sub-resources:
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
# Sample resource route with more complex sub-resources
# map.resources :products do |products|
# products.resources :comments
# products.resources :sales, :collection => { :recent => :get }
# end
# Sample resource route within a namespace:
# map.namespace :admin do |admin|
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
# admin.resources :products
# end
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
map.root :controller => "pictures"
# See how all your routes lay out with "rake routes"
# Install the default routes as the lowest priority.
# Note: These default routes make all actions in every controller accessible via GET requests. You should
# consider removing the them or commenting them out if you're using named routes and resources.
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
答案 2 :(得分:0)
它适用于Rails 2.3.4。你试过调试吗?我正在使用Netbeans,它会让我在第6行设置一个断点并运行它并检查各种变量等。
答案 3 :(得分:0)
你应该有map.resources :pictures
还有一个更好的想法让你的form_for指向该类的实例
<% form_for @picture, :html => {:multipart = true} do |form| %>
然后在你的控制器中确保你设置实例
@picture = Picture.new