在检查用户代理是否通过正确的域访问时,哪一项最有效.
如果他们使用某种Web代理访问域名(因为它往往会打破js),我们希望显示一个基于小js的"顶栏"样式警告.
我们考虑使用以下内容:
var r = /.*domain\.com$/;
if (r.test(location.hostname)) {
// showMessage ...
}
Run Code Online (Sandbox Code Playgroud)
这将照顾我们曾经使用的任何子域.
我们应该使用哪个主机名或主机名?
在Firefox 5和Chrome 12中:
console.log(location.host);
console.log(location.hostname);
Run Code Online (Sandbox Code Playgroud)
..两者显示相同.
是因为端口实际上不在地址栏中吗?
W3Schools说主机包含端口.
应该验证location.host/hostname还是我们可以在IE6 +中确定其他所有其他内容?
我试图将Ruby on Rails更新到3.1版.我跟着升级到Rails 3.1截屏视频,除了声明之外,所有内容似乎都有效
format.js { render(:update) { |page| page.redirect_to @article } }
Run Code Online (Sandbox Code Playgroud)
在许多控制器中,我有如下代码:
def create
...
respond_to do |format|
format.js { render(:update) { |page| page.redirect_to @article } }
end
end
Run Code Online (Sandbox Code Playgroud)
在上述所有情况下,当我尝试提交执行JS请求的相关表单时,我收到以下错误:
ActionView::MissingTemplate (Missing template articles/update, application/update with {:handlers=>[:erb, :builder, :coffee], :formats=>[:js, :html], :locale=>[:en, :en]}. Searched in:
* "/<MY_PROJECT_PATH>/app/views"
):
app/controllers/articles_controller.rb:114:in `create'
Rendered /<...>/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.3ms)
Run Code Online (Sandbox Code Playgroud)
我知道问题与RJS模板有关,因为它们在3.1版本中不再可用.因此,为了运行一些JavaScript代码,在我的控制器文件中,我可能\应该\可以插入一些JavaScript代码,如下例所示:
format.js { render :js => "alert('Hello Rails');" }
Run Code Online (Sandbox Code Playgroud)
BTW:... 但是,是否建议直接在控制器文件中使用JavaScript代码?
考虑到create控制器操作中的上述代码,我想@article在成功提交后将用户重定向到路径.我可以: …