문제

i am trying to run following curl command from my ruby code

Kernel.system'curl -H "Content-Type:application/json" -H "Accept:application/json" -d "{\"project\":{\"name\":\"BB\",\"description\":\"Book\"}}" "http://localhost:3000/company/projects?auth_token=mRFWyxfdPKHsDb4HhyLP"'

I want to do something like

name = "BB"(using a variable)

and then executing

Kernel.system'curl -H "Content-Type:application/json" -H "Accept:application/json" -d "{\"project\":{\"name\":"#{name}",\"description\":\"Book\"}}" "http://localhost:3000/company/projects?auth_token=mRFWyxfdPKHsDb4HhyLP"'

but this approach is not working...its taking #{name} as string.

Please help me with this.Let me know if i am doing something wrong.

Thanks.

도움이 되었습니까?

해결책

in order to enable string interpolation you will need to use double quotes in your string. The topic has been covered here: Double vs single quotes

also it would make your code better to read if you refactored it and assigned the parts to variables before joining them together into one string.

so:

host_name = 'stackoverflow.com'

Kernel.system 'curl -I #{host_name}' 

will not work whereas

Kernel.system "curl -I #{host_name}"

will

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top