2016-07-27 8 views
0

Wenn ich auf "Senden" auf meinem Formular drücke, wird es nicht an die Route: Erstellen weitergeleitet. Wenn ich "submit" drücke, geht es weiter zur neuen Route mit meinen Parametern in der URL. Ich habe gerade auf Rails 5 aktualisiert und Bootstrap verwendet. Habe keine Ahnung was ich falsch mache.Rails 5 wird mein Formular zum Erstellen der Route nicht senden

routes.rb

Rails.application.routes.draw do 
    root 'pizzas#index' 
    resources :pizzas 
    resources :toppings 
end 

Rails Routen

Prefix Verb URI Pattern     Controller#Action 
     root GET /       pizzas#index 
     pizzas GET /pizzas(.:format)   pizzas#index 
      POST /pizzas(.:format)   pizzas#create 
    new_pizza GET /pizzas/new(.:format)  pizzas#new 
    edit_pizza GET /pizzas/:id/edit(.:format) pizzas#edit 
     pizza GET /pizzas/:id(.:format)  pizzas#show 
      PATCH /pizzas/:id(.:format)  pizzas#update 
      PUT /pizzas/:id(.:format)  pizzas#update 
      DELETE /pizzas/:id(.:format)  pizzas#destroy 

PizzasController

class PizzasController < ApplicationController 
    def index 
    @pizzas = Pizza.all 
    end 

    def new 
    @pizza = Pizza.new 
    end 

    def create 
    @pizza = Pizza.new(pizza_params) 
    render text: params.inspect 
    end 

    private 

    def pizza_params 
    params.require(:pizza).permit(:name, :description) 
    end 
end 

new.html.erb Ansicht

<div class="container"> 
    <h1>Create Your Own Pizza:</h1> 

    <form class="form-horizontal"> 
    <%= form_for(@pizza) do |f| %> 

    <div class="form-group"> 
     <%= f.label :name %> 
     <%= f.text_field :name %> 
    </div> 

    <div class="form-group"> 
     <%= f.label :description %> 
     <%= f.text_field :description %> 
    </div> 

     <%= f.submit %> 

    <% end %> 
    </form> 
</div> 
+0

die '<% = form_for (@pizza) do | f | %> 'erstellt automatisch das -Tag, also hatten Sie 2, was inkorrekt HTML ist. Die äußere Form hatte keine Aktion, also tat sie nichts. –

Antwort

0

Ah Ich habe es herausgefunden, nachdem ich Stunden damit verbracht habe.

Aus irgendeinem Grund entspricht das Tag nicht. Nicht sicher, ob es sich um ein Rails-Problem oder Bootstrap handelt. Sie müssen sie in Tags wie folgt ändern:

<div class="container"> 
    <h1>Create Your Own Pizza:</h1> 

    <div class="form-horizontal"> // Changed this to a Div Tag 
    <%= form_for(@pizza) do |f| %> 

    <div class="form-group"> 
     <%= f.label :name %> 
     <%= f.text_field :name %> 
    </div> 

    <div class="form-group"> 
     <%= f.label :description %> 
     <%= f.text_field :description %> 
    </div> 

     <%= f.submit %> 

    <% end %> 
    </div> // Changed this to a Div Tag 
</div> 
Verwandte Themen