我遇到了一句话:
rake routes
在铁路路线内。
resources :assesments
Prefix Verb URI Pattern Controller#Action
assesments GET /assesments(.:format) assesments#index
POST /assesments(.:format) assesments#create
new_assesment GET /assesments/new(.:format) assesments#new
edit_assesment GET /assesments/:id/edit(.:format) assesments#edit
assesment GET /assesments/:id(.:format) assesments#show
PATCH /assesments/:id(.:format) assesments#update
PUT /assesments/:id(.:format) assesments#update
DELETE /assesments/:id(.:format) assesments#destroy
打印:
default: { action: :index}
和 Prefix Verb URI Pattern Controller#Action
assesments GET /assesments(.:format) assesments#index {:default=>{:action=>:index}}
POST /assesments(.:format) assesments#create {:default=>{:action=>:index}}
new_assesment GET /assesments/new(.:format) assesments#new {:default=>{:action=>:index}}
edit_assesment GET /assesments/:id/edit(.:format) assesments#edit {:default=>{:action=>:index}}
assesment GET /assesments/:id(.:format) assesments#show {:default=>{:action=>:index}}
PATCH /assesments/:id(.:format) assesments#update {:default=>{:action=>:index}}
PUT /assesments/:id(.:format) assesments#update {:default=>{:action=>:index}}
DELETE /assesments/:id(.:format) assesments#destroy {:default=>{:action=>:index}}
打印:
resources :assesments, defaults: {action: :index }
默认操作会发生什么变化?
rake routes
和 Prefix Verb URI Pattern Controller#Action
assesments GET /assesments(.:format) assesments#index
POST /assesments(.:format) assesments#create
new_assesment GET /assesments/new(.:format) assesments#new
edit_assesment GET /assesments/:id/edit(.:format) assesments#edit
assesment GET /assesments/:id(.:format) assesments#show
PATCH /assesments/:id(.:format) assesments#update
PUT /assesments/:id(.:format) assesments#update
DELETE /assesments/:id(.:format) assesments#destroy
现在看起来正常:
/*Intercepts the form submision*/
$('#myform').submit(function(e) {
/*sets send to true*/
var send = true;
/*foreach required element*/
$('.required').each(function() {
/*check if input is valid*/
if (!$(this).val()) {
/*if not valid, don't send and mark red*/
send = false;
$(this).css('background-color', 'red');
} else {
/*if valid, take away mark*/
$(this).css('background-color', 'none');
}
});
/*if don't send, prevent sending*/
if (!send) {
e.preventDefault();
return false;
}
});
答案 0 :(得分:0)
如果我们有
resources :assesments, defaults: { format: 'jpg' }, default: { format: 'xml'}
我们会访问localhost/assessments
而不是params
哈希看起来像:
{
"format"=>"jpg", # FROM defaults: {}
"default"=> { "format"=>"xml" }, # FROM default: {}
"controller"=>"assesments", WE CAN NOT CHANGE IT. COMES FROM RAILS
"action"=>"index" # WE CAN NOT CHANGE IT. COMES FROM RAILS
}
defaults: { anything_key: 'any_value' }
会将哈希内容添加到控制器内可访问的params
哈希值(但是您无法覆盖控制器提供的值 - 即::action
和:controller
)。
添加defaults: { action: :anything }
不会产生任何影响,但添加defaults: { format: 'jpg' }
会在路由范围包装的所有控制器中添加{ format: 'jpg' }
到params
哈希。
添加default: { some_key: 'value' }
会将此哈希(default: { some_key: 'value' }
)添加到由路由范围包装的控制器内的每个参数哈希。