Ich bin ziemlich neu in Ruby. Ich versuche, mit einem Tutorial für die Erstellung einer einfachen Buchung App zu folgen.Ruby on Rails erstellen Aktion funktioniert nicht
Meine Erstellungsaktion wird nicht funktionieren. Ich habe es versucht und es scheint etwas im Terminal zu tun, aber es fügt es nicht meinem Posts Objekt hinzu.
Hier ist meine Beiträge Controller:
class PostsController < ApplicationController
def index
@posts = Post.all
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def create
@post = Post.new(:title => params[:title], :content => params[:content])
@post.save
end
def edit
end
def update
end
def destroy
end
end
Hier ist meine neue Ansicht:
<h1>Add a New Post</h1>
<%= form_for @post do |f| %>
<p>
<%= f.label :title %>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :content %>
<%= f.text_area :content %>
</p>
<p>
<%= f.submit "Add a New Post" %>
</p>
<% end %>
Dies ist, was im Terminal nach oben kommt, wenn ich einreichen versuchen:
Started POST "/posts" for ::1 at 2016-08-31 17:54:39 -0700
ActiveRecord::SchemaMigration Load (16.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by PostsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"tGpevHtpEoP5jHYqCn1G7tUKX9YWnx+PWkqlPzKadTCiIEX1UGs96mSCrDf UIShKjp+ObwNA6G1nh3KE5gAIgw==", "post"=>{"title"=>"Jack's Post", "content"=>"Please use this post"}, "commit"=>"Add a New Post"}
(0.1ms) begin transaction
SQL (16.0ms) INSERT INTO "posts" ("created_at", "updated_at") VALUES (?, ?) [["created_at", 2016-09-01 00:54:40 UTC], ["updated_at", 2016-09-01 00:54:40 UTC]]
(14.7ms) commit transaction
No template found for PostsController#create, rendering head :no_content
Completed 204 No Content in 114ms (ActiveRecord: 31.3ms)
Ich habe das Gefühl, dass ich über eine Million Stack-Überlauf-Beiträge darüber gelesen habe und niemand scheint die Antwort zu haben. Jede Hilfe wäre sehr willkommen!
Starke Parameter können nicht durch das Tutorial, dass die OP folgt. Ich hatte nichts von ihnen gehört (ich bin immer noch auf Rails 3.x). Geh einfach! – Mick
Deshalb habe ich beide Lösungen zur Verfügung gestellt. :) @MickSharpe – codyeatworld
Vielen Dank! Es funktionierte! Ich bin mir nicht ganz sicher, ob ich verstehe, warum das funktioniert, aber ich bin mir sicher, dass ich es herausfinden werde, wenn ich weitermache. –