In my controller method, I am doing this
File.open ("#{RAILS_ROOT}/directory/
#{params[:file_name]}.#{params[:file_type]}", ‘w’) do |f|
f.write(params[:file_body])
end
but I am getting this error
NoMethodError (undefined method ` ' for
#ProgramsController:0xb66b4354):
I have tried passing the absolute path and still it doesn’t work. And
I have also tried escaping the whitespace between “.open” and
“(”…still doesn’t work.
I don’t know what I am doing wrong and how can I fix it?
Jatin K. wrote in post #962248:
In my controller method, I am doing this
File.open ("#{RAILS_ROOT}/directory/
#{params[:file_name]}.#{params[:file_type]}", ‘w’) do |f|
f.write(params[:file_body])
end
but I am getting this error
NoMethodError (undefined method ` ' for
#ProgramsController:0xb66b4354):
I have tried passing the absolute path and still it doesn’t work. And
I have also tried escaping the whitespace between “.open” and
“(”…still doesn’t work.
I don’t know what I am doing wrong and how can I fix it?
Hi Jatin K.,
It’s work for me. I am testing this on console. Please try this.
file_name = “test”
=> “test”
ext_name = “txt”
=> “txt”
File.open("#{RAILS_ROOT}/directory/#{file_name}.#{ext_name}", “w”) do |f|
f.write(“Hello World!”) end
=> 12