一个基本问题,我确定,但是我已经在这个特殊的砖墙上撞了好几天,令人尴尬。所以,我有一个名为' Country'的模型。
Routes.rb看起来像:
decalre
sqlstr VARCHAR2(30000);
cur SYS_REFCURSOR;
begin
SELECT SELECT LISTAGG(''''||LAYER||''' AS '||layer, ',') WITHIN GROUP (ORDER BY LAYER)
INTO sqlstr
FROM (SELECT LAYER FROM your_table GROUP BY LAYER);
sqlstr := 'SELECT * FROM your_table PIVOT (MIN(VALUESS) FOR layers IN ('||sqlstr||'))';
DBMS_OUTPUT.PUT_LINE(sqlstr);
OPEN cur FOR sqlstr;
...
end;
country_controller.rb看起来像:
Rails.application.routes.draw do
resources :country
resources :references
get 'homepage/home'
end
new.html是:
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
和_form.html.erb是
<%= render 'form', country: @country %>
在/ country / new上,我收到错误消息“country_path&#39;没有定义,我的意思是“country_path&#39 ;?而且我绝对迷失在这里我出错的地方。
干杯! 麦克
答案 0 :(得分:1)
关于多元化。 routes
和controllers
是复数,model
是单数。
# config/routes.rb
Rails.application.routes.draw do
resources :countries # <= HERE
resources :references
get 'homepage/home'
end
# apps/controllers/countries_controller.rb
class CountriesController < ApplicationController
# ...
end
另外,我知道这不是你问题的一部分,但也许你会想要将你的创建行动更新为:
def create
@country = Country.new(country_params)
if @country.save
redirect_to countries_path, notice: 'Country was successfully created.'
else
redirect_to :new, notice: 'Something went wrong :('
end
end
protected
def country_params
params.require(:country).permit(:name, :metatitle, :metadescription, :ogtitle, :ogdescription)
end
答案 1 :(得分:0)
在routes.rb
上你应该:
Rails.application.routes.draw do
resources :countries
end
除了你拥有的任何其他内容,更改是:resources :countries
应为复数