我收到以下错误
No route matches {:action=>"show", :controller=>"settings", :format=>nil}
尝试实施设置/新建。
我的设置/ new.html如下:
<h1>New setting</h1>
<%= form_for @setting do |f| %>
<% if @setting.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(@setting.errors.count, "error") %> prohibited this setting from being saved:</h2>
<ul>
<% @setting.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
</br></br>
Id: <%= f.text_field :id %><br>
Name: <%= f.text_field :name %><br>
<%= f.submit "Create" %>
<% end %>
我的routes.rb文件设置为:
resources :settings do
member do
post 'add'
post 'remove'
get 'settings/id'
end
collection do
get 'add'
get 'list' => "settings#index"
post 'get_settings'
get 'get_settings'
end
end
resources :settings
我的设置控制器:
class SettingsController < ApplicationController
# GET /Settings
# GET /Settings.json
def index
@settings = Setting.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @settings }
end
end
# GET /Settings/1
# GET /Settings/1.json
def show
@setting = Setting.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @setting }
end
end
# GET /Settings/new
# GET /Settings/new.json
def new
@setting = Setting.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @setting }
end
end
# GET /Settings/1/edit
def edit
@setting = Setting.find(params[:id])
end
# POST /Settings
# POST /Settings.json
def create
@setting = Setting.new(params[:setting])
respond_to do |format|
if @Setting.save
format.html { redirect_to @setting, notice: 'Lov value was successfully created.' }
format.json { render json: @setting, status: :created, location: @setting }
else
format.html { render action: "new" }
format.json { render json: @setting.errors, status: :unprocessable_entity }
end
end
end
# PUT /Settings/1
# PUT /Settings/1.json
def update
@setting = Setting.find(params[:id])
respond_to do |format|
if @Setting.update_attributes(params[:setting])
format.html { redirect_to @setting, notice: 'Lov value was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @setting.errors, status: :unprocessable_entity }
end
end
end
# DELETE /Settings/1
# DELETE /Settings/1.json
def delete
@setting = Setting.find(params[:id])
@setting.deleted = 1
@setting.save
respond_to do |format|
format.html { redirect_to settings_url }
format.json { render :json => { :success => true } }
end
end
end
我的佣金路线如下: -
add_settings POST /settings/:id/add(.:format) settings#add
remove_settings POST /settings/:id/remove(.:format) settings#remove
settings_id_settings GET /settings/:id/settings_id(.:format) settings#settings_id
add_settings_index GET /settings/add(.:format) settings#add
list_settings_index GET /settings/list(.:format) settings#index
get_settings_settings_index POST /settings/get_settings(.:format) settings#get_settings
GET /settings/get_settings(.:format) settings#get_settings
GET /settings(.:format) settings#index
POST /settings(.:format) settings#create
GET /settings/new(.:format) settings#new
GET /settings/:id/edit(.:format) settings#edit
GET /settings/:id(.:format) settings#show
PUT /settings/:id(.:format) settings#update
DELETE /settings/:id(.:format) settings#destroy
GET /settings(.:format) settings#index
POST /settings(.:format) settings#create
GET /settings/new(.:format) settings#new
GET /settings/:id/edit(.:format) settings#edit
GET /settings/:id(.:format) settings#show
PUT /settings/:id(.:format) settings#update
DELETE /settings/:id(.:format) settings#destroy
请检查并告知我们。
答案 0 :(得分:0)
成功保存后,您的Create
操作正在重定向到Show
。
但是,即使您的控制器采用routes.rb
方法,您的Show
也没有Show
的条目。
您可以尝试运行此命令rake routes
吗?这将列出您的rails应用程序的所有有效路由。
答案 1 :(得分:0)
您只需要使用资源:路由文件和rails中的设置RESTFUL路由将处理所有事情。您不需要明确说明HTTP动词的静止路由 同样在控制器的创建和更新操作中,使用@setting而不是@Setting。