[英]Strange Routing error in rails 3.2
I am implementing an application in which i want to change the settings of the application. 我正在实现一个应用程序,我想在其中更改应用程序的设置。 While doing so I am getting an error
这样做我得到一个错误
no routes matches {:action=>"show", :controller=>"settings", format=>"nil"}
while clicking on the open new settings
tab. 点击打开的
new settings
标签。
my index.html
is as follows:- 我的
index.html
如下: -
<h1>Listing settings</h1>
<table class="table table-striped table-bordered">
<tr>
<th>ID</th>
<th>Name</th>
<th>Value</th>
<th>Description</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<% @settings.each do |c| %>
<tr>
<td><%= c.id %> </td>
<td><%= c.name %> </td>
<td><%= c.value %> </td>
<td><%= c.description %> </td>
<td><%= link_to 'Edit', {:action => 'edit', :id => c.id} %> </td>
<td><%= link_to 'Delete', {:action => 'delete', :id => c.id},
:data => { :confirm => "Are you sure you want to delete this value?" } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Setting', {:action => 'new'} %>
My settings controller
is as follows:- 我的
settings controller
如下: -
class SettingsController < ApplicationController
# GET /setting
# GET /setting.json
def index
@settings = Setting.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @settings }
end
end
# GET /setting/1
# GET /setting/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 /setting/new
# GET /setting/new.json
def new
@setting = Setting.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @setting }
end
end
# GET /setting/1/edit
def edit
@setting = Setting.find(params[:id])
end
# POST /setting
# POST /setting.json
def create
@setting = Setting.new(params[:setting])
respond_to do |format|
if @setting.save
format.html { redirect_to @setting, notice: 'Setting 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 /setting/1
# PUT /setting/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: 'Setting 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 /setting/1
# DELETE /setting/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
My new.html
is as follows:- 我的
new.html
如下: -
<h1>New settings</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 %>
Id: <%= f.text_field :id %><br>
Name: <%= f.text_field :name %><br>
Values: <%= f.text_field :value %><br>
Description: <%= f.text_field :description %><br>
<% end %>
<%= link_to 'Back', settings_path %>
My routes.rb is as follows:- 我的routes.rb如下: -
Lms::Application.routes.draw do
resources :books do
member do
post 'add'
post 'remove'
end
collection do
get 'add'
get 'list' => "books#index"
post 'get_books'
get 'get_books'
end
end
resources :books
resources :book_transactions
resources :book_issues
resources :book_holds
resources :categories
resources :users
resources :admins
resources :library_locations
resources :lov_values
resources :loan_fines
resources :lov_names
resources :loans_fines do
member do
post 'add'
post 'remove'
end
collection do
get 'add'
get 'list'
post 'get_loans_fines'
get 'get_loans_fines'
end
end
resources :settings do
member do
post 'add'
post 'remove'
end
collection do
get 'add'
get 'list'
post 'get_settings'
get 'get_settings'
end
end
root :to => 'books#index'
match ':controller(/:action(/:id))(.:format)'
The strange part is that when i click on new
action it is going/redirecting to the show
action..I am a bit confused why this is happening.. 奇怪的是,当我点击
new
动作时它会/重定向到show
动作..我有点困惑为什么会发生这种情况..
Can some one help me with this.. 有人可以帮我弄这个吗..
To check your routes you can run 要检查您的路线,您可以运行
rake routes
耙路线
to inspect if you have the routes defined correctly. 检查您是否正确定义了路线。 Also I would suggest to use
我也建议使用
<%= link_to "New Setting", new_setting_pah %>
For your routes definition you are not defining the routes for other methods than add or remove. 对于您的路由定义,您没有定义除添加或删除之外的其他方法的路由。 I advise you to read this great tutorial on rails routes
我建议你阅读这条关于rails路线的精彩教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.