ruby-on-rails - 无法为我的 rails 应用程序添加表单
问题描述
我对论坛、rails 和编程非常陌生。我只是在构建一个应用程序来组织我的钢琴调音。
我有一个调优模型tuning.rb
class Tuning < ApplicationRecord
has_many :tuneds
accepts_nested_attributes_for :tuneds
validates :Client, presence: true
validates :Tel, presence: true
validates :Address, presence: true
geocoded_by :Address
after_validation :geocode
def start_time
self.scheduled_date.start
end
end
它有_许多调谐。我的 tunes 模型是 tune.rb
class Tuned < ApplicationRecord
belongs_to :tuning
accepts_nested_attributes_for :tuning
end
我想在调音显示视图中显示我的调音表格,如下所示 [显示表格][1]
我已经将它嵌入到 simple_form
<%= simple_form_for :tuneds do |r| %>
<%= r.input :pitch %>
<%= r.input :payment %>
<%= r.input :work_done %>
<%= r.button :submit %>
<% end %>
然而它并没有在我上面的记录列中添加记录,我知道这很有效,因为我可以通过控制台添加它们。它没有出现在控制台或显示页面上[提交时不显示记录][2]
谢谢您的帮助!埃文
[1]: https://i.stack.imgur.com/JZ2vR.png
[2]: https://i.stack.imgur.com/87k7A.png
class TuningsController < ApplicationController
before_action :set_tuning, only: [:show, :edit, :update, :destroy]
# GET /tunings
# GET /tunings.json
# how to get them to appear only upcoming Tuning.where('scheduled_date' => Date.today)
def index
@tunings = Tuning.all.order('scheduled_date DESC')
add_breadcrumb "Home", :root_path
add_breadcrumb "All Tunings"
if params[:search].present?
@tunings = Tuning.all
@hash = Gmaps4rails.build_markers(@tunings) do |user, marker|
marker.lat user.latitude
marker.lng user.longitude
@list =Tuning.find(params[:id])
@json = @list.to_gmaps4rails
@tuneds = Tuned.all? { |
| }
end
end
end
Tuning_controller controller
# GET /tunings/1
# GET /tunings/1.json
def show
add_breadcrumb "Up-coming tunings", :root_path
end
def current
@tuning_current = Tuning.where(['scheduled_date > ?', 1.day.ago]).order('scheduled_date ASC')
add_breadcrumb "Home", :root_path
add_breadcrumb "Up-coming Tunings", :tunings_current_path
end
def bookagain
six_months = 6.months.ago
@tuning_bookagain = Tuning.where(['scheduled_date < ?', 6.months.ago])
add_breadcrumb "Home", :root_path
add_breadcrumb "re-book", :tunings_bookagain_path
end
def reports
add_breadcrumb "Home", :root_path
add_breadcrumb "Reports", :tunings_reports_path
end
# GET /tunings/new
def new
@tuning = Tuning.new
add_breadcrumb "Up-coming tunings", :root_path
end
# GET /tunings/1/edit
def edit
end
# POST /tunings
# POST /tunings.json
def create
@tuning = Tuning.new(tuning_params)
respond_to do |format|
if @tuning.save
format.html { redirect_to @tuning, notice: 'Tuning was successfully added.' }
format.json { render :show, status: :created, location: @tuning }
else
format.html { render :new }
format.json { render json: @tuning.errors, status: :unprocessable_entity }
end
end
add_breadcrumb "Up-coming tunings", :root_path
end
# PATCH/PUT /tunings/1
# PATCH/PUT /tunings/1.json
def update
respond_to do |format|
if @tuning.update(tuning_params)
format.html { redirect_to @tuning, notice: 'Tuning was successfully updated.' }
format.json { render :show, status: :ok, location: @tuning }
else
format.html { render :edit }
format.json { render json: @tuning.errors, status: :unprocessable_entity }
end
end
add_breadcrumb "home", :root_path
end
# DELETE /tunings/1
# DELETE /tunings/1.json
def destroy
@tuning.destroy
respond_to do |format|
format.html { redirect_to tunings_url, notice: 'Tuning was successfully deleted.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_tuning
@tuning = Tuning.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def tuning_params
params.require(:tuning).permit(:Client, :scheduled_date, :Tel, :Address, :Quote, :Type, :Make, :Model, :Work_done, :Work_needed, :Comments, :Paid, :Initial_contact, :Sn)
end
Tuned_controller:
class TunedsController < ApplicationController
def index
@tuning = Tuning.find(params[:tuning_id])
@tuneds = @tuning.tuneds.create(tuneds.params)
end
end
再次感谢
它很可能将 id 传递给 tunes 模型?我得到的错误是“没有路线匹配 [POST] “/tunings/51”
解决方案
推荐阅读
- python - 使用请求的响应时间极长
- mysql - 使用 sequelize.literal() 替换
- mysql - 如何用 HQL 替换 JForm 中的 MySQL 插入参数化查询?
- hadoop - 如何在蜂巢中实现百分位数
- scala - 从地图生成邻接矩阵
- vue.js - 使用搜索功能设置 v-autocomplete
- excel - 使用 Excel 正确计算(和求和)分子量
- mysql - SQL查询中Regex的使用
- spring-boot - ConfigMap 不适用于 application.properties 但适用于 application.yml
- amazon-web-services - 没有 S3 存储桶的 AWS Cloudfront CORS 标头