简体   繁体   English

语法错误,意外的'}',期望':'Rails

[英]syntax error, unexpected '}', expecting ':' Rails

我想删除此部分: "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"但出现错误,语法错误,意外的是“}”,期望为“:”

@iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/#{current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}" : "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"}" 

You can't use double quotes( " ) inside double quotes. You need to escape those quotes: 您不能在双引号中使用双引号( " )。您需要转义那些引号:

"Hello, "are you there?" # doesn't make sense in Ruby
"Hello, \"are you there?" # escaped double quotes inside the string

Try like this 试试这样吧

val = current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}" : "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"

@iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/}#{val}" 

Or 要么

g = "https://www.google.co.in/"

q = %[helo #{"world #{g}"}]

=> "helo world https://www.google.co.in/"

Try it 试试吧

@iframe_statistics_url = %[#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/companies.html?#{current_user.has_role?(:administrator) ? admin_token_url : "#{token_url}&company=#{URI.encode(current_company.trylive_name)}"}] 

@VtrKanna @VtrKanna

@iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/#{current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}" : "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"}"

this is work fine but my problem is just to keep this part 这很好,但是我的问题是保留这部分

@iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/#{current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}"}" 

this is result an error 这是结果错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM