views:

191

answers:

4

I'm coding with Ruby on rails 2.3.2 under BitNami RubyStack. When I call the upload controller, I get error like this:

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 ')'

The code of index view:

<% 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 %>

String number 6 is:

<%= submit_tag "Upload" %>

What's the problem? Please, help me.

A: 

Try

<% 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 %>

And add

# routes.rb
map.resources :pictures
Lichtamberg
Lichtambergoh, now i'm gettingundefined method `picture_path' for #<ActionView::Base:0x3ea4d60>
Anton
for the new code that u have wrtteni get undefined method `merge' for "First Name":String
Anton
Do you have the pictures controller in your routes.rb?
Lichtamberg
yes! of courseI have it.
Anton
Please show me your routes.rb..
Lichtamberg
And try the code above now.. i changed the form.label to label..
Lichtamberg
Try to add map.resources :pictures
Lichtamberg
btw you can see your active routes with "rake routes" in your command shell
Lichtamberg
Lichtamberg thank u so muchHow i can do your reputation bigger?
Anton
You can accept my answer as the right one :) (what you already did). You are welcome
Lichtamberg
but i don't understand why i should ADD 'map.resources :pictures'to route.rb?
Anton
have a look at http://api.rubyonrails.org/classes/ActionController/Routing.html or http://guides.rubyonrails.org/routing.html. Named routes are only recognised by the entries in routes.rb. The default routs would recognise if you put "http://asd.com/pictures" in your browser, but it wouldnt recognise the "pictures_path" in your view!
Lichtamberg
Sorry for wrong spelling: i ment: have a look at api.rubyonrails.org/classes/ActionController/… or guides.rubyonrails.org/routing.html. Named routes are only recognised by the entries in routes.rb. The default routes would be recognise f.e. if you put "asd.com/pictures" in your browser, but rails woulnt recognise the "pictures_path" in your view unless you havent defined it in your routes.rb!
Lichtamberg
A: 
    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
Anton
A: 

It works for me in Rails 2.3.4. Did you try debugging it? I'm using Netbeans, and it'll let me set a breakbpoint on line 6 and run it and inspect the various variables etc.

JRL
JRLNo. I didn'tWhich version of Ruby do u use? Do u working under Linux?
Anton
A: 

you should have a map.resources :pictures

also its a better idea to have your form_for point to an instance of that class

<% form_for @picture, :html => {:multipart = true} do |form| %>

then in your controller make sure you set the instance

@picture = Picture.new
ErsatzRyan