我是 Rails 新手。尝试实施创建操作时出现以下错误。
Routing Error
No route matches {:action=>"show", :controller=>"settings", :format=>nil}
我的控制器文件如下:-
@settings = Setting.new(params[:settings])
respond_to do |format|
if @settings.save
format.html { redirect_to @settings, notice: 'Setting was successfully created.' }
format.json { render json: @settings, status: :created, location: @settings }
else
format.html { render action: "new" }
format.json { render json: @settings.errors, status: :unprocessable_entity }
end
end
结尾
我的 Routes.rb 文件如下:-
resources :settings do
member do
post 'add'
post 'remove'
get 'settings/id'
end
collection do
get 'add'
get 'list'
post 'get_settings'
get 'get_settings'
end
end
resources :settings
我的 rake 路线有以下几点:-
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
我的 create.html.erb 如下:_
<%= 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" %>
我的错误日志是:-
Started GET "/settings/new" for 127.0.0.1 at 2013-03-12 18:57:09 +0530
Processing by SettingsController#new as HTML
Rendered settings/new.html.erb within layouts/application (170.2ms)
Completed 500 Internal Server Error in 1112ms
ActionController::RoutingError (No route matches {:action=>"show", :controller=>
"settings", :format=>nil}):
app/views/settings/new.html.erb:7:in `_app_views_settings_new_html_erb__979995
802_23360592'
app/controllers/settings_controller.rb:29:in `new'
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.1
1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within resc
ues/layout (0.0ms)
我的 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>
First Name: <%= f.text_field :name %><br>
<%= f.submit "Create" %>
<% end %>
<%= link_to 'Back', settings_path %>
谁能帮帮我吗。