Я уверен, что это довольно простой вопрос, но я несколько дней смущающе бился головой об эту кирпичную стену. Итак, у меня есть модель под названием «Страна».
Routes.rb выглядит так:
Rails.application.routes.draw do
resources :country
resources :references
get 'homepage/home'
end
country_controller.rb выглядит так:
class CountryController < ApplicationController
before_action :set_country, only: [:show, :edit, :update, :destroy]
def new
@country = Country.new
end
def create
@country = Country.new(:name => params[:name], :metatitle => params[:metatitle], :metadescription => params[:metadescription], :ogtitle => params[:ogtitle], :ogdescription => params[:ogdescription], :abouthtml => params[:abouthtml])
if @country.save
redirect_to country_index_path, notice: 'Country was successfully created.'
else
redirect_to :new, notice: 'Something went wrong :('
end
end
def update
if @country.update
redirect_to country_index_path, notice: 'Country was successfully created.'
else
redirect_to :new, notice: 'Something went wrong :('
end
end
end
new.html:
<%= render 'form', country: @country %>
и _form.html.erb равен
<div class="form">
<%= form_with(model: country, local: true) do |f| %>
<div class="form_element">
<%= f.label "Name" %>
<%= f.text_field :name %>
</div>
<div class="form_element">
<%= f.label "Meta Title" %>
<%= f.text_field :metatitle %>
</div>
<div class="form_element">
<%= f.label "Meta Description" %>
<%= f.text_field :metadescription %>
</div>
<div class="form_element">
<%= f.label "OG_Title" %>
<%= f.text_field :ogtitle %>
</div>
<div class="form_element">
<%= f.label "OG_Description" %>
<%= f.text_field :ogdescription %>
</div>
<div class="form_element">
<%= f.label "abouthtml" %>
<%= f.text_field "About (HTML)" %>
</div>
<%= f.submit %>
<% end %>
</div>
В / country / new, я получаю сообщение об ошибке, говорящее, что 'country_path' не определен, и я имел в виду 'country_path'? И я абсолютно заблудился относительно того, где я ошибся здесь.
Ура!
Mike