ruby

Rails devise_token_auth gem, how do I set password reset link?

感情迁移 提交于 2021-01-27 07:00:09
问题 I have a problem for using password reset function of this gem. https://github.com/lynndylanhurley/devise_token_auth This is from the document. /password/edit GET "Verify user by password reset token. This route is the destination URL for password reset confirmation. This route must contain reset_password_token and redirect_url params. These values will be set automatically by the confirmation email that is generated by the password reset request." When users forget theirs passwords, they can

Add `Authorization Bearer` hash to Net::HTTP post request (Ruby)

半世苍凉 提交于 2021-01-27 06:59:23
问题 How can I add Authorization Bearer to a POST request with Net::HTTP ? I can only find help for "basic authentication" in the documentation. req.basic_auth 'user', 'pass' Source: https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html#class-Net::HTTP-label-Basic+Authentication I'm trying to replicate a curl that would look like: > curl 'http://localhost:8080/places' -d '{"_json":[{"uuid":"0514b...", > "name":"Athens"}]}' -X POST -H 'Content-Type: application/json' -H > 'Authorization: Bearer

How does Ruby enumerator terminate iteration?

匆匆过客 提交于 2021-01-27 06:28:44
问题 Friends, please I need help with this explanation: In the Ruby code below, what condition termites the loop do? It's supposed to be an infinite loop, but, how does it terminate? # Ruby code fib = Enumerator.new do |y| a = b = 1 loop do y << a a, b = b, a + b end end p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] Your contributions will be highly appreciated. 回答1: (Source: https://rossta.net/blog/infinite-sequences-in-ruby.html) The way you have implemented the function fib allows it

HAML Form For Rails

白昼怎懂夜的黑 提交于 2021-01-27 05:54:27
问题 I'm currently trying to convert an ERB layout to HAML. This is the error I keep receiving: index.html.haml:18: syntax error, unexpected ')' ));}\n #{_hamlout.format_... Here is the HAML page: .row-fluid .span6 %h2 Todo List .span6 %h2{:style => "text-align:right;"} <script>document.write(today)</script> %hr.divider .row-fluid .span6 %h2.small_head New Task = render :partial => 'layouts/form_errors', :locals => {:object => @list} .form = form_for :list, :url => {:controller => 'lists', :action

method's local variable with same name as another method

前提是你 提交于 2021-01-27 05:29:33
问题 I was trying to figure out how Ruby handles local variables that have the same names as the methods in self class, and found a behavior that I do not understand: class A def val 10 end def test val = val end end p A.new.test this code prints nil . why?! 回答1: I think that the local variable is declared as soon as it's enunciated. In ruby the lookup is first to look for a local variable, if it exists it's used, and if not it looks for a method. This would mean that val = val declares the first

Kill a process called using open3 in ruby

◇◆丶佛笑我妖孽 提交于 2021-01-27 04:46:29
问题 I'm using a command line program, it works as mentioned below: $ ROUTE_TO_FOLDER/app < "long text" If "long text" is written using the parameters "app" needs, then it will fill a text file with results. If not, it will fill the text file with dots continuously (I can't handle or modify the code of "app" in order to avoid this). In a ruby script there's a line like this: text = "long text that will be used by app" output = system("ROUTE_TO_FOLDER/app < #{text}") Now, if text is well written,

How do I remove HTML encoded characters from a string?

风流意气都作罢 提交于 2021-01-27 04:39:40
问题 I have a string which contains some HTML encoded characters and I want to remove them: "<div>Hi All,</div><div class=\"paragraph_break\">< /></div><div>Starting today we are initiating PoLS.</div><div class=\"paragraph_break\"><br /></div><div>Please use the following communication protocols:<br /></div><div>1. Task Breakup and allocation - Gravity<br /></div><div>2. All mail communications - BC messages<br /></div><div>3. Reports on PoC / Spikes: Writeboard<br /></div><div>4. Non story

Uploading a file using the Ruby SDK to Amazon S3

蓝咒 提交于 2021-01-27 04:31:11
问题 I am trying to upload a file. A simple hello.txt. I was following the docs, and I am unable to upload it to my bucket. # START AWS CLIENT s3 = Aws::S3::Resource.new bucket = s3.bucket(BUCKET_NAME) begin s3.buckets[BUCKET_NAME].objects[KEY].write(:file => FILE_NAME) puts "Uploading file #{FILE_NAME} to bucket #{BUCKET_NAME}." bucket.objects.each do |obj| puts "#{obj.key} => #{obj.etag}" end rescue Aws::S3::Errors::ServiceError # rescues all errors returned by Amazon Simple Storage Service end

Uploading a file using the Ruby SDK to Amazon S3

心不动则不痛 提交于 2021-01-27 04:30:27
问题 I am trying to upload a file. A simple hello.txt. I was following the docs, and I am unable to upload it to my bucket. # START AWS CLIENT s3 = Aws::S3::Resource.new bucket = s3.bucket(BUCKET_NAME) begin s3.buckets[BUCKET_NAME].objects[KEY].write(:file => FILE_NAME) puts "Uploading file #{FILE_NAME} to bucket #{BUCKET_NAME}." bucket.objects.each do |obj| puts "#{obj.key} => #{obj.etag}" end rescue Aws::S3::Errors::ServiceError # rescues all errors returned by Amazon Simple Storage Service end

ruby on rails: heroku: Missing `secret_key_base` for 'production' environment

大憨熊 提交于 2021-01-27 04:21:05
问题 I added the key into heroku config var, but I'm still getting the error. Is this the correct way? I ignored secrets.yml as I read from other sources that its not a good idea to push this to the public. in the heroku config var: [key] SECRET_KEY_BASE [value] 3280570382948240938 in secrets.yml production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> What am I still doing wrong? Furthermore, if I put my secret keys into heroku's config variable, don't other developers get to see this too? So,