Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
prom candy
Dec 16, 2005

Only I may dance
Don't be, seeing action in the Rails thread makes me feel relevant again!

Adbot
ADBOT LOVES YOU

Pardot
Jul 25, 2001




lol Ruby 2.4
https://twitter.com/hubertlepicki/status/806469337611640833

Waroduce
Aug 5, 2008
I just installed ruby 2.3.3 like two days ago! :downs:

xenilk
Apr 17, 2004

ERRYDAY I BE SPLIT-TONING! Honestly, its the only skill I got other than shooting the back of women and calling it "Editorial".

serious question, who thought this would be a good idea?? I can agree that change is good, but changes like that is seriously loving scary, no?

Edit: Ok so reading more into it it's supposed to align with a certain standard... so the reasoning behind it has some legimacy... but holy crap this is still scary.

xenilk fucked around with this message at 01:56 on Dec 8, 2016

xtal
Jan 9, 2011

by Fluffdaddy
That's nothing compared to the date parsing changes in 1.9

Slow News Day
Jul 4, 2007

xenilk posted:

serious question, who thought this would be a good idea?? I can agree that change is good, but changes like that is seriously loving scary, no?

Edit: Ok so reading more into it it's supposed to align with a certain standard... so the reasoning behind it has some legimacy... but holy crap this is still scary.

look at it on the bright side: when your boss asks you why revenues have declined significantly, you can tell them it was literally a rounding error!

xenilk
Apr 17, 2004

ERRYDAY I BE SPLIT-TONING! Honestly, its the only skill I got other than shooting the back of women and calling it "Editorial".

enraged_camel posted:

look at it on the bright side: when your boss asks you why revenues have declined significantly, you can tell them it was literally a rounding error!

hahah I guess it's the perfect case as to why money should be treated in cents or at least with decimals, right? :P

Waroduce
Aug 5, 2008
:dukedoge:
So i sat with the guy who is like the department liasion between dev and implementation today. He's got some coding experience as he's responsible for all the scripts we currently run and he walked me through putting all this together.

This actually works, which is whats the most important to me, but i'd be curious to see what ya'll though about how we went about it...

I ripped his login process from an importation script we run, so i didn't write that all.

He helped me define the different steps irt def get_signatures and all that

he also helped me define classes and explain what that was

You guys really helped me by i giving me the vocabulary to explain what i want to do and a framework with how to do it in relation to hashes and arrys because when i started talking to him, he was like....I don't use hashes I don't really know how to interact with them....and than you guys really helped me think of my concept in like a ruby programming way and how it would work

Please review my lovely coding that took me literally 8 hours to do

code:
require 'csv'
require 'highline'
require 'watir-webdriver'

class SignatureSetup

  def initialize(instance = "", username="", password="")
    @b = Watir::Browser.new :chrome
    @username = username
    @password = password
    @instance = instance
    @forms = []
  end

  def login
    @b.goto "https://#{@instance}.company.com"
    @b.input(name: "user[username]").send_keys @username
    @b.input(name: "user[password]").send_keys @password
    @b.input(name: "commit").click
    @b.div(id: "content_wrap").wait_until_present(99999)
  end

  def get_signature_settings
    arry = CSV.read('sigs.csv',headers:true).to_a

    hashes = [ ]
    arry.each_with_index do |row, index|
      next if index == 0
      hashes << Hash[arry[0].zip(row)]
    end
    
    hashes.each do |hash|
      staffsigs = ""
      reviewsigs = ""
      title = ""
      formdata = []
      hash.each do |key, value|
        title = value if key == "Name"
        if value == "y" && key.include?("Staff")
          staffsigs << "#{key.gsub(" Staff","")} "
        elsif value == "y" && key.include?("Review")
          reviewsigs << "#{key.gsub(" Review","")} "
        end
      end
      formdata << title << staffsigs << reviewsigs
      @forms << formdata
    end
  end

  def update_evaluation
    Watir::Wait.until {@b.button(id: "form_submit").text == "Update"}
    @b.button(id: "form_submit").click
    Watir::Wait.until {@b.button(id: "form_submit").text == "Update"}
  end

  def set_evaluation(form)
    set_signatures(form[1], "staff") unless form[1] == ""
    set_signatures(form[2], "review") unless form[2] == ""
    update_evaluation
    @b.goto "#{@instance}.company.com/evaluations"
  end 

  def iterate_and_set_evaluations
    @forms.each do |form|
      begin
        p form
        @b.span(text: /#{Regexp.escape(form[0].strip)}/).click
        set_evaluation(form)
      rescue Watir::Exception::UnknownObjectException => ex
        puts "An error of type #{ex.class} happened, message is #{ex.message}"
        next
      end
    end
  end 

  def set_signatures(users_string, type)
    user_boxes = @b.checkboxes(id: /#{type}_user_title/)
    users = users_string.split(" ")
    users.each do |user|
      user_boxes.each do |box|


       box.set if box.parent.text.include? user
      end
    end
  end

  def steps
    login
    @b.goto "#{@instance}.company.com/evaluations"
    get_signature_settings
    iterate_and_set_evaluations
  end
end

cli = HighLine.new

ins = cli.ask("What is the name of the instace you are working in?")

username = cli.ask("What is your username?")

password = cli.ask("What is your password?") { |q| q.echo ="*" }

gogogo = SignatureSetup.new(ins, username, password)

gogogo.steps

:dukedoge:

I still need to specify client signatures but that is a task for tomorrow

Waroduce fucked around with this message at 05:53 on Dec 8, 2016

xtal
Jan 9, 2011

by Fluffdaddy
That code is pretty good actually. You're on the right track using a plain Ruby object and organizing it in logical, short functions.

To be constructive, try to picture how you would adapt this code such that the class takes fewer arguments and no method is over five lines. Even experienced Ruby developers have trouble with this, but following Sandi Metz' rules will force you to write good OO code. You'll be compelled to make more, smaller plain Ruby objects.

xtal fucked around with this message at 13:19 on Dec 8, 2016

Seat Safety Switch
May 27, 2008

MY RELIGION IS THE SMALL BLOCK V8 AND COMMANDMENTS ONE THROUGH TEN ARE NEVER LIFT.

Pillbug
Honestly, that's a head above what I see juniors produce out of school. Not bad at all for a first project.

necrotic
Aug 2, 2005
I owe my brother big time for this!

enraged_camel posted:

look at it on the bright side: when your boss asks you why revenues have declined significantly, you can tell them it was literally a rounding error!

Don't use floats for money :(

Waroduce
Aug 5, 2008
I have a quick question regarding adding a colom for client signatures....

my complete code is above but if i wanted to add the ability to check on/off client sigs I would do this:

code:

hashes.each do |hash|
  staffsigs = ""
  reviewsigs = ""
  title = ""
  clientsigs = ""
  hashes.each do |key, value|
    puts "Key:#{key}, Value:#{value}
       title = value if key == "Name"
        if value == "y" && key.include?("Staff")
          staffsigs << "#{key.gsub(" Staff","")} "
        elsif value == "y" && key.include?("Review")
          reviewsigs << "#{key.gsub(" Review","")} "
         elseif value == "y" && key.include?("Client")
           clientsigs << "#{key.gsub(" Client","")} "
      end
      formdata << title << clientsigs << staffsigs << reviewsigs
      @forms << formdata
    end
  end


I think i'm missing an end command somewhere....and does the order of my elseif statements matter in relation to the formdata << title << clientsigs so on and so forth?


E: I'm gunna have a really weird competency level after I finish this

Waroduce fucked around with this message at 18:40 on Dec 8, 2016

kayakyakr
Feb 16, 2004

Kayak is true

necrotic posted:

Don't use floats for money :(

Yup. Integers in cents is the right way to do it.

Really not looking forward to migrating away from that mistake :-/

Waroduce
Aug 5, 2008
Also how would I make it read Y,y, or Yes,yes/ N,n,no,Noinstead of just y?

I can restrict input on the excel spreadsheet to accept only the value I've built the code w but it's not very elegant

Slow News Day
Jul 4, 2007

necrotic posted:

Don't use floats for money :(

I don't. I just wanted to crack a joke!

The Journey Fraternity
Nov 25, 2003



I found this on the ground!
Ruby on Rails Love-In: Office Space now a reality

necrotic
Aug 2, 2005
I owe my brother big time for this!

kayakyakr posted:

Yup. Integers in cents is the right way to do it.

Really not looking forward to migrating away from that mistake :-/

We do 10-5 for those sweet fractional cents. Fortunately we had always done integer cents, but we started at 10-2 hard coded and moving to 10-5 was quite a trick. We essentially store an exponent field for all monetary values now, which allowed us to start translating to the higher precision safely.

necrotic fucked around with this message at 18:06 on Dec 9, 2016

necrotic
Aug 2, 2005
I owe my brother big time for this!

Waroduce posted:

Also how would I make it read Y,y, or Yes,yes/ N,n,no,Noinstead of just y?

I can restrict input on the excel spreadsheet to accept only the value I've built the code w but it's not very elegant
code:
YES_VALUES = %w(y yes)

# later
YES_VALUES.include?(value.downcase)
String#downcase makes a string all lowercase characters.

Array#include? returns true if the provided argument exists in the array.

%w() is shorthand for initializing an array of simple string values.

necrotic fucked around with this message at 18:10 on Dec 9, 2016

Waroduce
Aug 5, 2008
So the VP really likes my script and wants to build it out and make it a standard part of our implementation process. He doesn't know dick about coding, but he wants to add features like having it rip form names out of the baseline and generate a csv/excel file, embed hyperlinks of the forms into the name and some other poo poo.

He wants me to write a scope of work for our implementation process which is a whole can of worms and do one for my script. Like where does it fit and what should it accomplish.

So this may be a bit beyond the scope of the thread but you guys have helped me so far, what are some resources or tips for writing a scope of work for this script/software thing before the vp dumps this on development and tells them to make it happen.

Pardot
Jul 25, 2001





Whew, looks like Matz said no to this and it's rolled back https://bugs.ruby-lang.org/issues/12958#note-18 :sweatdrop:

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

Pardot posted:

Whew, looks like Matz said no to this and it's rolled back https://bugs.ruby-lang.org/issues/12958#note-18 :sweatdrop:

Nice to see sanity win one.

prom candy
Dec 16, 2005

Only I may dance

Waroduce posted:

So the VP really likes my script and wants to build it out and make it a standard part of our implementation process. He doesn't know dick about coding, but he wants to add features like having it rip form names out of the baseline and generate a csv/excel file, embed hyperlinks of the forms into the name and some other poo poo.

He wants me to write a scope of work for our implementation process which is a whole can of worms and do one for my script. Like where does it fit and what should it accomplish.

So this may be a bit beyond the scope of the thread but you guys have helped me so far, what are some resources or tips for writing a scope of work for this script/software thing before the vp dumps this on development and tells them to make it happen.

I like user stories as a way to define the scope of a software project.

Peristalsis
Apr 5, 2004
Move along.
Time to necro this thread.

I'm trying to use Capybara to test a file upload page. It's a simple page with a file upload field constructed with a file_field_tag helper, a text box, and a submit button.

I've tried having Capybara click on the "Select File" button, but I can't access (or even see) the file selector dialog that comes up, so I can't select a file.

I've tried using page.attach_file(<file control name>, <File path>) and then clicking on the submit button, but the controller doesn't receive any file param for me to work with.

I'm not sure what else to try here. Is attach_file just a way to directly set the value of the form parameter before submitting? If not, is there a way to do that?

necrotic
Aug 2, 2005
I owe my brother big time for this!
Does it work outside of Capybara, manually? The form itself may be missing the correct incantation to enable uploads.

http://guides.rubyonrails.org/form_helpers.html#uploading-files note the multipart option on the form tag.

Peristalsis
Apr 5, 2004
Move along.

necrotic posted:

Does it work outside of Capybara, manually? The form itself may be missing the correct incantation to enable uploads.

http://guides.rubyonrails.org/form_helpers.html#uploading-files note the multipart option on the form tag.

I'll be damned. It was working before (at least to the point of being able to set a debugger in the controller and examine the file object), but when I just double-checked it, that's failing now, too. Sounds like a good problem to pick up Monday morning. (Or, more likely, tomorrow, since I'm way behind on this project.)

Thanks for the sanity check.

Peristalsis
Apr 5, 2004
Move along.

necrotic posted:

Does it work outside of Capybara, manually? The form itself may be missing the correct incantation to enable uploads.

http://guides.rubyonrails.org/form_helpers.html#uploading-files note the multipart option on the form tag.


Peristalsis posted:

I'll be damned. It was working before (at least to the point of being able to set a debugger in the controller and examine the file object), but when I just double-checked it, that's failing now, too. Sounds like a good problem to pick up Monday morning. (Or, more likely, tomorrow, since I'm way behind on this project.)

Thanks for the sanity check.

Okay, now it works manually, but the test fails in the same way: It uses page.attach_file to attach the file to the form, then clicks the submit button. When it gets to the controller, params['test_file'] doesn't exist.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Does anyone have a good setup for tallying events/data somehow? Like using for A/B testing tracking metrics server-side?

We've been using Datadog/statsd, but it messes with the numbers in weird ways.

manero
Jan 30, 2006

EVGA Longoria posted:

Does anyone have a good setup for tallying events/data somehow? Like using for A/B testing tracking metrics server-side?

We've been using Datadog/statsd, but it messes with the numbers in weird ways.

statsd can do weird things if you have your retention settings wrong, but it really is the gold standard. I was just reading these articles this weekend:

https://kevinmccarthy.org/2013/07/18/10-things-i-learned-deploying-graphite/

https://matt.aimonetti.net/posts/2013/06/26/practical-guide-to-graphite-monitoring/


Otherwise, a simple counter in Redis could get you what you want, just make sure you have it's persistence configured correctly so you don't lose data.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Thanks, reading those makes me wonder if it's something wrong with datadog's dashboard.

Specifically, I have metrics that I'm sending as a count (whole numbers), and displaying as the sum of that count for the last hour, and it's coming out with decimals like it's a rate. Any ideas?

manero
Jan 30, 2006

EVGA Longoria posted:

Thanks, reading those makes me wonder if it's something wrong with datadog's dashboard.

Specifically, I have metrics that I'm sending as a count (whole numbers), and displaying as the sum of that count for the last hour, and it's coming out with decimals like it's a rate. Any ideas?

I don't have any experience with DataDog, but perhaps it's trying to average things out across a time bucket?

I just found this in the FAQ:

http://docs.datadoghq.com/faq/#why-is-my-counter-metric-showing-decimal-values

http://docs.datadoghq.com/guides/metrics/#counters

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Is it possible to create duplicate RAILS_ENVs, just with different names? We run a couple of staging environments that use the Production rails env, which is rough for monitoring/tracking. I'd like to split it out, so that we can have a production and a staging config -- but without having to maintain the same config in 2 files (they will inevitably drift).

manero
Jan 30, 2006

EVGA Longoria posted:

Is it possible to create duplicate RAILS_ENVs, just with different names? We run a couple of staging environments that use the Production rails env, which is rough for monitoring/tracking. I'd like to split it out, so that we can have a production and a staging config -- but without having to maintain the same config in 2 files (they will inevitably drift).

I kind of feel you can't have it both ways. Either you create a separate RAILS_ENV and have duplication between staging and production, or just run production everywhere.

What sort of things are you running into with monitoring?

If you're following 12 Factor (https://12factor.net/config) -- you probably should be -- push all the actual environment-specific stuff into ENV. I do this with separate staging and production "environments" for a client's app on Heroku, but they are both running as RAILS_ENV=production.

I'm using Honeybadger for app monitoring, and they support a HONEYBADGER_ENV setting, so you can be running RAILS_ENV=production on multiple apps, but then set HONEYBADGER_ENV=staging, and it shows up as a separate environment of the same app in the Honeybadger UI.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

manero posted:

I kind of feel you can't have it both ways. Either you create a separate RAILS_ENV and have duplication between staging and production, or just run production everywhere.

What sort of things are you running into with monitoring?

If you're following 12 Factor (https://12factor.net/config) -- you probably should be -- push all the actual environment-specific stuff into ENV. I do this with separate staging and production "environments" for a client's app on Heroku, but they are both running as RAILS_ENV=production.

I'm using Honeybadger for app monitoring, and they support a HONEYBADGER_ENV setting, so you can be running RAILS_ENV=production on multiple apps, but then set HONEYBADGER_ENV=staging, and it shows up as a separate environment of the same app in the Honeybadger UI.

Yeah, I got tired of duplicating staging and production configs and now do it all through ENV. It's especially good on Heroku, because I can pre-configure for a bunch of our commonly used addons by checking for certain ENV vars and have adding/removing them Just Work

EVGA Longoria
Dec 25, 2005

Let's go exploring!

manero posted:

I kind of feel you can't have it both ways. Either you create a separate RAILS_ENV and have duplication between staging and production, or just run production everywhere.

What sort of things are you running into with monitoring?

If you're following 12 Factor (https://12factor.net/config) -- you probably should be -- push all the actual environment-specific stuff into ENV. I do this with separate staging and production "environments" for a client's app on Heroku, but they are both running as RAILS_ENV=production.

I'm using Honeybadger for app monitoring, and they support a HONEYBADGER_ENV setting, so you can be running RAILS_ENV=production on multiple apps, but then set HONEYBADGER_ENV=staging, and it shows up as a separate environment of the same app in the Honeybadger UI.

It's monitoring things like the honeybadger you mention, but we've got a lot of places. I was hoping I could have it both ways, but if not, I guess we'll start using another variable.

necrotic
Aug 2, 2005
I owe my brother big time for this!
ENV everything you can. But in a pinch you could probably make a shared env file that you load in the specific environment files with any env specific settings only set in that specific envs file.

But using ENV is way better.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

necrotic posted:

ENV everything you can. But in a pinch you could probably make a shared env file that you load in the specific environment files with any env specific settings only set in that specific envs file.

But using ENV is way better.

Most things already use ENV, it's more about not having to adjust a lot of existing code to read the name of the env instead of from Rails.env

necrotic
Aug 2, 2005
I owe my brother big time for this!
You push the env value into the rails config, don't reference it directly in app code.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

cross posting my noob question from the SQL thread:

quote:

Huge noob Postgres question inbound:

SQL code:
myapp::DATABASE=> refresh materialized view X;
ERROR:  could not write block 386 of temporary file: No space left on device
can someone help me I've never seen this before. It's a PG database via Heroku if that makes any difference. Obviously I'm out of space but I have no idea where to clean it up. Running VACUUM didn't help.

necrotic
Aug 2, 2005
I owe my brother big time for this!
I'd open a support ticket with heroku.

Adbot
ADBOT LOVES YOU

KoRMaK
Jul 31, 2012



Is there any solution to the n+1 problem in rails for update/creates?

I have an object that has a relationship to many other objects and I need to update all those other objects. Ideally, I'd like the sql generated to be one giant insert statement, rather than many little ones.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply