Я пытаюсь создать новый объект интерфейса.После нажатия кнопки «Создать» она все равно остается new.html.erb
, она должна перейти на project_interfaces_path
(главная страница).Кроме того, данные еще не сохранены.
Я пробовал много способов, таких как изменение URL, но он не работает, и он сообщает NoMethodError в InterfacesController # create undefined метод `interfaces 'для nil: NilClass
interface/new.html.erb
<div class="card-body">
<%= form_for @interface, url:project_interfaces_path,method: :post do |f| %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_area :name,class: 'form-control'%>
</div>
<div class="form-group">
<%= f.label :desp %>
<%= f.text_field :desp,class:'form-control'%>
</div>
<div class="form-group">
<%= f.label :request_url %>
<%= f.text_field :request_url,class:'form-control'%>
</div>
<div class="form-group">
<%= f.label :request_eg %>
<%= f.text_field :request_eg,class:'form-control'%>
</div>
<div class="form-group">
<%= f.label :response_eg %>
<%= f.text_field :response_eg,class:'form-control'%>
</div>
<%=link_to project_interfaces_path do%>
<button type="button" class="btn btn-primary">返回列表</button>
<% end %>
<%=f.submit "创建",class: 'btn btn-primary' %>
<% end %>
Контроллер интерфейса:
def new
@interface = Interface.new
end
def create
@interface = @project.interfaces.new(interface_params)
if @interface.save
redirect_to project_interfaces_path
else
render :new
end
end
private
def interface_params
params.require(:interface).permit(:id, :name, :desp,:request_url,:request_eg,:response_eg)
end
Интерфейс принадлежит проекту:
class Interface < ApplicationRecord
belongs_to :method_type
has_many :get_fields, dependent: :destroy
has_many :put_fields, dependent: :destroy
belongs_to :project
end