新红宝石,我面临一个小问题..交易需要一双崭新的眼睛FYI红宝石:开始交易,回滚
的:我不使用支架,这样我可以理解一步一步红宝石建筑的过程。
当我尝试添加一个新的演出,它不保存在数据库中,我看到我的服务器日志下面的错误...
Started POST "/gigs" for ::1 at 2017-03-06 17:34:34 +0300
Processing by GigsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"lDSSVGuQDFlKwdkP8m1Gk4rzA4wG03wzpd5LmA19HZM7LPOLSrDBYGSsRRvwRZTbfVoe/HZmeGxBjRwVnZSKBw==", "gig"=>{"name"=>"Perry Dillard", "budget"=>"500", "duration"=>"4", "startdate"=>"19-Jan-1971", "description"=>"Reprehenderit, eligendi natus consequatur, dicta quae corporis voluptatem, ut pariatur. Consequatur excepteur natus eos, eos cum et eiusmod.", "location"=>"Dicta beatae culpa ut nostrud nihil voluptatem Eum", "open"=>"true", "hired"=>"1"}, "commit"=>"post it"}
(0.1ms) begin transaction
(0.1ms) rollback transaction
Redirected to http://localhost:3000/gigs
Completed 302 Found in 3ms (ActiveRecord: 0.1ms)
Started GET "/gigs" for ::1 at 2017-03-06 17:34:34 +0300
Processing by GigsController#index as HTML
Rendering gigs/index.html.erb within layouts/application
Rendered gigs/index.html.erb within layouts/application (0.6ms)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
Rendered layouts/_nav.html.erb (1.6ms)
Completed 200 OK in 29ms (Views: 26.7ms | ActiveRecord: 0.2ms)
这是我的形式
<div class="container">
\t <h4 class ="center">Post an Internship Opportunity</h4>
\t <br>
<div class="col-sm-8">
<%= form_for @gig do |f| %>
\t <div class= "row">
\t \t <div class="col-sm-10">
\t \t \t <div class="form-group">
\t \t \t \t <%= f.label :name %>
\t \t \t \t <%= f.text_field :name, autofocus: true, class: "form-control input-lg" %>
\t \t \t \t <small class="healer block"> Data entry, writer, receptinist etc </small>
\t \t \t </div><!-- /.form-group -->
\t \t </div>
\t \t <div class="col-sm-3">
\t \t \t <div class="form-group">
\t \t \t \t <%= f.label :budget %>
\t \t \t \t <%= f.text_field :budget, class: "form-control" %>
\t \t \t \t <small class="healer block"> Free or min Kshs 5000 </small>
\t \t \t </div><!-- /.form-group -->
\t \t </div>
\t \t <div class="col-sm-4">
\t \t \t <div class="form-group">
\t \t \t \t <%= f.label :duration %>
\t \t \t \t <%= f.text_field :duration, class: "form-control" %>
\t \t \t \t <small class="healer block"> 2 weeks, 1 month, 3 months </small>
\t \t \t </div>
\t \t </div>
\t \t <div class="col-sm-3">
\t \t \t <div class="form-group">
\t \t \t \t <%= f.label :startdate %>
\t \t \t \t <%= f.text_field :startdate, class: "form-control" %>
\t \t \t </div><!-- /.form-group -->
\t \t </div>
\t \t <div class="col-sm-10">
\t \t \t <div class="form-group">
\t \t \t \t <%= f.label :description %>
\t \t \t \t <%= f.text_area :description, class: "form-control" %>
\t \t \t \t <small class="healer block"> What are the expectations and working hours, mentorship opportunities etc </small>
\t \t \t </div><!-- /.form-group -->
\t \t </div>
\t \t <div class="col-sm-10">
\t \t \t <div class="form-group">
\t \t \t \t <%= f.label :location %>
\t \t \t \t <%= f.text_field :location, class: "form-control " %>
\t \t \t \t <small class="healer block"> ignore if same location with your registered office </small>
\t \t \t </div><!-- /.form-group -->
\t \t </div>
\t \t <div class="col-sm-5">
\t \t \t <div class="form-group">
\t \t \t \t <%= f.label :open %>
\t \t \t \t <%= f.text_field :open, class: "form-control" %>
\t \t \t </div><!-- /.form-group -->
\t \t </div>
\t \t <div class="col-sm-5">
\t \t \t <div class="form-group">
\t \t \t \t <%= f.label :hired %>
\t \t \t \t <%= f.text_field :hired, class: "form-control" %>
\t \t \t </div><!-- /.form-group -->
\t \t </div>
\t \t <div class="col-sm-10">
\t \t \t <div class="form-group">
<button type="submit" class="btn btn-secondary btn-block"> <%= f.submit "post it" %> </button>
</div>
</div>
\t \t </div>
\t \t <% end %>
</div><!-- /.col-* -->
这是我演出控制器
class GigsController < ApplicationController
\t def index
\t \t
\t end
\t def new
\t \t @gig = Gig.new
\t end
\t def create
\t \t @gig = Gig.new(gig_params)
\t \t @gig.save
\t \t redirect_to @gig
\t end
\t
#private stuff
\t private
\t def gig_params
\t \t params.require(:gig).permit(:name, :description, :budget, :startdate, :duration, :location, :open, :hired)
\t end
end
觉得它可能会帮助,如果我加入我的架构?
create_table "gigs", force: :cascade do |t|
t.string "name"
t.text "description"
t.integer "budget"
t.date "startdate"
t.integer "duration"
t.string "location"
t.boolean "open", default: true
t.integer "hired"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "category_id"
t.integer "user_id"
t.index ["category_id"], name: "index_gigs_on_category_id"
t.index ["user_id"], name: "index_gigs_on_user_id"
end
添加千兆模型以及
class Gig < ActiveRecord::Base
\t has_many \t :proposals
\t belongs_to \t :user
\t belongs_to \t :category
\t has_many \t :abilities
\t has_many \t :skills, through: :abilities
end
很可能你有一些失败的验证 - 请张贴'Gig'型号代码。 – eugen
嗨欧根,我添加了演出模型 – samgichuru
在GigsController#create中将您的代码从'@gig.save'更改为'@ gig.save!'。您将在控制台输出中看到验证错误。 –