Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1

    Errore: ActionController::RoutingError in Books#show

    Ciao a tutti.

    Sono alle prime armi con Ruby e devo dire che è molto interessante: sti studiando su un testo di Filippo Costalli completo e scorrevole.

    Sono riuscito a creare il primo script che interagisce con un db mysql.

    Però ho un problema nell'inserimento dei dati nel db mysql: i dati vengono registrati in mysql però appare quest'errore che non so cosa sia:

    Errore pagina successiva per problemi di lunghezza.
    Potete aiutarmi?
    Grazie

  2. #2
    codice:
    ActionController::RoutingError in Books#show 
    Showing app/views/books/show.html.erb where line #42 raised: 
    
    edit_book_url failed to generate from {:action=>"edit", :controller=>"books", :id=>#<Book ID: 3, TITOLO: "c", ANNO: 2009, AUTORE: "c", EDITORE: "c", PAGINE: 10, PREZZO: #<BigDecimal:381e0cc,'0.1036E2',8(8)>, ISBN: 12>}, expected: {:controller=>"books", :action=>"edit"}, diff: {:id=>#<Book ID: 3, TITOLO: "c", ANNO: 2009, AUTORE: "c", EDITORE: "c", PAGINE: 10, PREZZO: #<BigDecimal:381d578,'0.1036E2',8(8)>, ISBN: 12>}
    
    Extracted source (around line #42): 
    
    39: </p>
    40: 
    41: 
    42: <%= link_to 'Edit', edit_book_path(@book) %> |
    43: <%= link_to 'Back', books_path %>
    
    
    
    RAILS_ROOT: C:/biblioteca
    
    Application Trace | Framework Trace | Full Trace 
    C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-
    ....
    C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb:13:in `run'
    C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111
    C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3
    Request
    Parameters: 
    
    {"id"=>"3"}
    
    Show session dump
    
    --- 
    
    Response
    Headers: 
    
    {"Content-Type"=>"text/html",
     "Cache-Control"=>"no-cache"}

  3. #3
    Come hai scritto il file di routing?
    Lì dice che non vuole l'ID per l'editing. :master:

    PS. Ruby != Rails

  4. #4
    Sono un principiante scusa .... adesso dà un altro errore sulla pagina app/views/books/index.html.erb sulla riga rossa:

    codice:
    <h1>Listing books</h1>
    
    <table>
      <tr>
        <th>Id</th>
        <th>Titolo</th>
        <th>Anno</th>
        <th>Autore</th>
        <th>Editore</th>
        <th>Pagine</th>
        <th>Prezzo</th>
        <th>Isbn</th>
      </tr>
    
    <% @books.each do |book| %>
      <tr>
        <td><%=h book.ID %></td>
        <td><%=h book.TITOLO %></td>
        <td><%=h book.ANNO %></td>
        <td><%=h book.AUTORE %></td>
        <td><%=h book.EDITORE %></td>
        <td><%=h book.PAGINE %></td>
        <td><%=h book.PREZZO %></td>
        <td><%=h book.ISBN %></td>
        <td><%= link_to 'Show', book %></td>   
        <td><%= link_to 'Edit', edit_book_path(book) %></td>
        <td><%= link_to 'Destroy', book, :confirm => 'Are you sure?', :method => :delete %></td>
      </tr>
    <% end %>
    </table>
    
    
    
    
    <%= link_to 'New book', new_book_path %>

  5. #5
    Forse se tu postassi anche l'errore... inoltre, aggiungi il file di Routing, senza quello non so dirti il problema. Apparentemente il codice è corretto.

  6. #6
    L'errore è questo:

    codice:
    ActionController::RoutingError in Books#show 
    Showing app/views/books/show.html.erb where line #42 raised: 
    
    edit_book_url failed to generate from {:action=>"edit", :controller=>"books", :id=>#<Book ID: 3, TITOLO: "c", ANNO: 2009, AUTORE: "c", EDITORE: "c", PAGINE: 10, PREZZO: #<BigDecimal:381e0cc,'0.1036E2',8(8)>, ISBN: 12>}, expected: {:controller=>"books", :action=>"edit"}, diff: {:id=>#<Book ID: 3, TITOLO: "c", ANNO: 2009, AUTORE: "c", EDITORE: "c", PAGINE: 10, PREZZO: #<BigDecimal:381d578,'0.1036E2',8(8)>, ISBN: 12>}
    
    Extracted source (around line #42): 
    
    39: </p>
    40: 
    41: 
    42: <%= link_to 'Edit', edit_book_path(@book) %> |
    43: <%= link_to 'Back', books_path %>
    Qual'è il file di routing ?
    In quale cartella si trova?

    L'applicazione è l'img allegata.
    Immagini allegate Immagini allegate

  7. #7
    Il file di routing si chiama routes.rb e si trova in config.

  8. #8
    Originariamente inviato da weppos
    Il file di routing si chiama routes.rb e si trova in config.
    OK grazie ho capito, ecco routes.rb:

    codice:
    ActionController::Routing::Routes.draw do |map|
      map.resources :books
    
      map.resources :books
    
      # 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 => "welcome"
    
      # 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

  9. #9
    Perché hai due

    codice:
    ActionController::Routing::Routes.draw do |map|
      map.resources :books
    
      map.resources :books
    ?

    Apparentemente il codice è corretto.
    Posta il codice dell'azione Books#show e quello del template corrispondente.

  10. #10
    Scusa non ho capito... dove trovo i files che mi chiedi?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.