ruby-on-rails - 保存到数据库后,年份属性为零 - 不从表单转移
问题描述
我的年份属性没有从表单下拉菜单中转移。我不确定我哪里出错了。
我的表格:
<%= simple_form_for @movie do |f| %>
<div class="form-group">
<%= f.input :title, placeholder: "Movie Title", input_html: { class: 'form-control' } %>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<%= f.input :year, as: :date,
start_year: Date.today.year,
end_year: Date.today.year - 100,
discard_day: true, order: [:year],
input_html: { class: 'form-control' } %>
</div>
控制器代码:
class MoviesController < ApplicationController
before_action :find_movie, only: [:show, :edit, :update, :destroy]
def index
end
def new
@movie = Movie.new
end
def create
@movie = Movie.new(movie_params)
if @movie.save
redirect_to movie_path(@movie)
else
flash[:danger] = "Please try again!"
redirect_to new_movie_path
end
end
private
def find_movie
@movie = Movie.find(params[:id])
end
def movie_params
params.require(:movie).permit(:title, :year, :genre, :poster, :director, :plot, :rating, :list_ids => [])
end
end
它在视图中看起来和工作正常,但是当我检查数据库时,年份为零。有任何想法吗?
解决方案
推荐阅读
- javascript - JS函数在执行后的特定时间内自禁用
- java - 无法创建 android 架构组件 AndroidViewModel 实例。尝试制作一个简单的 Room DB
- java - 使用一份 Jasper 报告生成 2 个文档
- html - UI-选择默认占位符而不是可以更改
- python-3.x - DNS 查询未指定或太小
- c++ - 无法使用基类右值初始化指向子类的指针
- xml - Haskell - 如何将 XML 响应解析为 Haskell 数据类型?
- node.js - 不能在异步函数上调用 nodeify 但可以调用 then()
- android - ScrollView 内的 ConstraintLayout,constraintHeight_percent 中断滚动
- laravel - 使用 Laravel + Vue 正确处理 404 响应