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
Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.
Weird. Does it also fail in irb for you?

Adbot
ADBOT LOVES YOU

Pardot
Jul 25, 2001




Lexicon posted:

Weird. Does it also fail in irb for you?

It does, in fact. Odd.

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.

Pardot posted:

It does, in fact. Odd.

I am very disappointed in ruby today. This was causing a bug in my project that took hours to identify.

Pardot
Jul 25, 2001




Lexicon posted:

I am very disappointed in ruby today. This was causing a bug in my project that took hours to identify.

Well it's just some bug with irb, ruby itself is fine

$ ruby -r 'active_support/all' -e 'r = {a: 1, until: 2}.stringify_keys; p r'
{"a"=>1, "until"=>2}

Obsurveyor
Jan 10, 2003

Pardot posted:

Well it's just some bug with irb, ruby itself is fine

$ ruby -r 'active_support/all' -e 'r = {a: 1, until: 2}.stringify_keys; p r'
{"a"=>1, "until"=>2}


Yeah, it doesn't seem to like the new hash syntax:

code:
1.9.3-p392 :002 > {a: 1, until: 2}.stringify_keys
1.9.3-p392 :003?>
code:
1.9.3-p392 :030 > { :a => 1, :until => 2 }.stringify_keys
 => {"a"=>1, "until"=>2}

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.

Pardot posted:

Well it's just some bug with irb, ruby itself is fine

$ ruby -r 'active_support/all' -e 'r = {a: 1, until: 2}.stringify_keys; p r'
{"a"=>1, "until"=>2}


Yeah, that's a fair point. I was just stepping through logic in rails console under the [faulty assumption] the parser was the same. Banging my head against the wall when it was hanging on one of these. Anyway - a rather compelling reason to use pry!

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug
I suspect irb thinks until: is until, the reverse of while.

code:
> ruby -e 'i = 0; until i == 5; i += 1; puts i; end'
1
2
3
4
5

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.

Cocoa Crispies posted:

I suspect irb thinks until: is until, the reverse of while.

code:
> ruby -e 'i = 0; until i == 5; i += 1; puts i; end'
1
2
3
4
5

Oh for sure, it totally is. It fails similarly with 'if' and 'unless'. Non-conditional keywords like 'class' are apparently fine.

kitten smoothie
Dec 29, 2001

This is a pretty good read if you haven't seen it, root cause analysis of the Github mass email incident from Tuesday.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
3.2.13 is such a clusterfuck.

Obsurveyor
Jan 10, 2003

Smol posted:

3.2.13 is such a clusterfuck.

Can you elaborate?

manero
Jan 30, 2006

Obsurveyor posted:

Can you elaborate?

They included the security vulnerability updates, plus a bunch of other changes that ended up causing performance and other regressions.

Civil Twilight
Apr 2, 2011

Good summary of it here: http://blog.bugsnag.com/2013/03/20/rails-3-2-13-performance-regressions-major-bugs/

Obsurveyor
Jan 10, 2003


This must all be ActiveRecord related(which I don't use) because I haven't seen any of those dev server slow response issues upgrading from 3.0 to 3.2 along with the rest of my gems over the last couple days. Finally got all my specs/features passing again. Probably should have done this sooner since my cucumber runs went from 5 minutes to less than a minute.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
It's apparently Sprockets related, so I guess it depends on how heavily you're using that.

Sub Par
Jul 18, 2001


Dinosaur Gum
I'm a newb at Rails stuff but I've followed the Rails Tutorial that was recommended here, and now I have a small app. I am playing around with the Facebook API using Omniauth-Facebook and Koala, which is going well. But I want to to set up something like this:

1) User logs in to my site using their email and password, gets a session with a token that's stored in the user table and is a random base64 string (SecureRandom.urlsafe_base64) - this is done and works fine.

2) I have an app on Facebook. User clicks a button on my site once logged in to authorize the app. This is handled via OmniAuth. This is done-ish.

3) Facebook generates a token which I persist and then I generate session/cookie that tracks them

What I'm having a hard time with is #3 - I'm generally following this for the Omniauth stuff, but I don't know enough about how sessions work to know if I can simply create a second session for the same user or if I have to create a different controller for the Facebook session type? Basically I want to be sure that my app knows which session to look at when doing stuff on my site (logging in, logging out, changing their contact info) versus doing stuff on my site via Facebook (using the FB session and token). Hopefully this makes sense?

Sil
Jan 4, 2007

Sub Par posted:

I'm a newb at Rails stuff but I've followed the Rails Tutorial that was recommended here, and now I have a small app. I am playing around with the Facebook API using Omniauth-Facebook and Koala, which is going well. But I want to to set up something like this:

1) User logs in to my site using their email and password, gets a session with a token that's stored in the user table and is a random base64 string (SecureRandom.urlsafe_base64) - this is done and works fine.

2) I have an app on Facebook. User clicks a button on my site once logged in to authorize the app. This is handled via OmniAuth. This is done-ish.

3) Facebook generates a token which I persist and then I generate session/cookie that tracks them

What I'm having a hard time with is #3 - I'm generally following this for the Omniauth stuff, but I don't know enough about how sessions work to know if I can simply create a second session for the same user or if I have to create a different controller for the Facebook session type? Basically I want to be sure that my app knows which session to look at when doing stuff on my site (logging in, logging out, changing their contact info) versus doing stuff on my site via Facebook (using the FB session and token). Hopefully this makes sense?

Also a noob, but it sounds to me as if you are overcomplicating things. You don't need more than one session. Your User's session is stored in
code:
session
just add extra stuff inside there that you want to track. For instance, I want to remember my user's name in a session
code:
session[:user_name]=User.find(session[:user_id]).name
.

Session is just a Hash. It has an :id=>'122343123414232' member, presumably :user_id => something, and whatever else you want to put in it. The Session is also stored as a cookie on the user's computer, by default. At least I'm pretty sure it is.

Be careful with putting important unencrypted info in it, otherwise go hog wild. Well, hog wild without making it too large(4kb max size?).

Disclaimer, again, I'm also a noob.

e. Actually the session variable itself is just session, I think session[:user_id] is just an extra member.

e2. Here's the official reference, though I find it fairly complicated. There are various ways to debug rails applications(ie. stop it's operation and see what's stored in various variables). Whenever you hit an error you should be able to see the session hash and stare at what's in it. If you have something like https://github.com/charliesome/better_errors you even get a console to play around with. I think it's even better if you can use pry, but I haven't gotten around to figuring it out yet(not that it looks hard, just gotta do it).

The point being, play around with sessions in whatever way you want and just manually raise errors at some point in execution so you can get inside your variables at that time.

Sil fucked around with this message at 18:19 on Mar 21, 2013

Sub Par
Jul 18, 2001


Dinosaur Gum
Excellent, thank you, I think that puts me on the right track.

Sub Par
Jul 18, 2001


Dinosaur Gum
Ok so now I'm trying to troubleshoot an error. I can't reproduce it in development, the thing works just fine there. But when I deploy to Heroku and Facebook hits /auth/facebook/callback, I get a 500 - internal server error.

I can't figure out why that would be happening. Heroku logs says:

code:
2013-03-22T20:21:49+00:00 heroku[router]: at=info method=GET path=/auth/facebook
/callback host=shrouded-woodland-XXXX.herokuapp.com fwd="98.195.155.246" dyno=we
b.1 queue=0 wait=0ms connect=2ms service=27ms status=500 bytes=643
Which isn't super helpful to me. Is there some way to get a more verbose error?

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
It's been a while, but I think the free logs are like that. You could add some exception notification gem to your app though.

Sub Par
Jul 18, 2001


Dinosaur Gum
Yeah after an hour of failing I just paid the $12 for Exceptional and got my back trace in seconds. A++ would buy again.

Pardot
Jul 25, 2001




Anything you print to stdout will get picked up by logplex and show up in `heroku logs --tail` or any drains you set up. I thought rails did this automatically, but checked a rails project i have and saw I'm using the rails_log_stdout gem, then remembered from way back when that rails by default logs to files.

Pardot fucked around with this message at 00:11 on Mar 25, 2013

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."
Does anyone have a good gem for a popup overlay? Basically when a button is pressed, I'd like to see a form pop up with some info from the page the button was on, and some blank form fields for a user to add info into.

So let's say you're on the Pink Floyd Dark Side of the Moon page. You click "Add to collection" and a popup appears asking you to check what formats you have the album in (CD, vinyl, etc) and quantity.

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.

I think what you're asking about is a modal? Are you using jQuery UI? Because that has a modal control built in. You can nest forms in modals and submit them with ajax if that's your thing.

e; http://jqueryui.com/dialog/

MrDoDo
Jun 27, 2004

You better remember quick before we haul your sweet ass down to the precinct.

raej posted:

Does anyone have a good gem for a popup overlay? Basically when a button is pressed, I'd like to see a form pop up with some info from the page the button was on, and some blank form fields for a user to add info into.

So let's say you're on the Pink Floyd Dark Side of the Moon page. You click "Add to collection" and a popup appears asking you to check what formats you have the album in (CD, vinyl, etc) and quantity.

Something like a lightbox?

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."

MrDoDo posted:

Something like a lightbox?

Something similar, but with another page. In this case it would be /collection/add which is a form, from the /albums/1 with populating info from /albums/1 in the /collection/add form.

MrDoDo
Jun 27, 2004

You better remember quick before we haul your sweet ass down to the precinct.

raej posted:

Something similar, but with another page. In this case it would be /collection/add which is a form, from the /albums/1 with populating info from /albums/1 in the /collection/add form.

You can do an AJAX request to populate the div for the lightbox with the collections form. Auto populate the field you need from from the selected album then post to the collection when you submit the form. I have done something similar and that was the way I did it.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

MrDoDo posted:

You can do an AJAX request to populate the div for the lightbox with the collections form. Auto populate the field you need from from the selected album then post to the collection when you submit the form. I have done something similar and that was the way I did it.

Start with a link or button to go to a new view that has the collections form. Add a remote: option that does that over AJAX and puts it in a lightbox (you may need to teach the action how to render without a layout). That way you get progressive enhancement.

MrDoDo
Jun 27, 2004

You better remember quick before we haul your sweet ass down to the precinct.

Cocoa Crispies posted:

Start with a link or button to go to a new view that has the collections form. Add a remote: option that does that over AJAX and puts it in a lightbox (you may need to teach the action how to render without a layout). That way you get progressive enhancement.

This would probably be the best way start out, thanks for that :)

KoRMaK
Jul 31, 2012



I am building a file attachment system. I know there are gems out there that do this, but I'm doing it by hand. Things are going well, I have successfully saved the data into the database (yes, into the DB) and successfully retrieved it and delivering it to the user via web browser.

My question is how do I read that file back into an object that I can then do file.content_type on? I'm running into wierd problems where ruby complains that it is a string and not a file or something.

Ruby code:
    file_image = params[:attachment][:file_data].read
    file = StringIO.new(file_image)
    
    Rails.logger.info("file content type #{params[:attachment][:file_data].content_type} file.content_type #{file.content_type}") #file.content_type gives an error

wolffenstein
Aug 2, 2002
 
Pork Pro
Security things to look out for in Rails 3 and 4.

prom candy
Dec 16, 2005

Only I may dance

KoRMaK posted:

I am building a file attachment system. I know there are gems out there that do this, but I'm doing it by hand. Things are going well, I have successfully saved the data into the database (yes, into the DB) and successfully retrieved it and delivering it to the user via web browser.

My question is how do I read that file back into an object that I can then do file.content_type on? I'm running into wierd problems where ruby complains that it is a string and not a file or something.

Ruby code:
    file_image = params[:attachment][:file_data].read
    file = StringIO.new(file_image)
    
    Rails.logger.info("file content type #{params[:attachment][:file_data].content_type} file.content_type #{file.content_type}") #file.content_type gives an error

You seem to know that what you're doing is nuts, why are you doing it? Just as an exercise?

KoRMaK
Jul 31, 2012



I actually don't have any compelling evidence to use to convince the team against it, so I am complicit.

Even if I do get evidence against it, I'd still like to know how to solve my problem as a learning exercise.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Save it to a separate column in the database. A StringIO doesn't know anything about content types.

Sil
Jan 4, 2007
It IS a string? I think #new expects a path or link to open?

Why not use Paperclip-database? https://github.com/softace/paperclip_database

Why it's a bad idea: I think the simple answer is that you having Amazon/Dropbox store and deliver your files is presumably cheaper than delivering it from Heroku or your own server or whatever. Furthermore I think Amazon S3 and Dropbox store the files at multiple locations around the world, making their delivery speed even better. I don't know if this is actually true(as in I've seen it mentioned as opposed to read studies done about it), and it all depends on your own server anyway.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
StringIO is not a string. Think of it as an IO object backed by a string instead of a file or a network socket.

Sub Par
Jul 18, 2001


Dinosaur Gum
I'm looking to store a person's username in the database (Postgres - Heroku) as entered but add a case-insensitive unique index on the username column. So for example, I want a user to be able to sign up as "MyUserName" and have my application display the username as entered, while still disallowing other users from signing up as "myusername".

The only solution I can find on google is to downcase/upcase the username prior to shoving it into the DB since Postgres' unique indexes are case sensitive by default. This accomplishes uniqueness, but doesn't allow me to display the username as entered. Were I operating in the database, I would just
code:
CREATE UNIQUE INDEX IX_Unique_Username ON users (lower(username))
But it seems to me there should be some way to just do this in my migration? If that's not possible I guess I can just have a second column called display_username or something but that seems kind of dumb.

kitten smoothie
Dec 29, 2001

This'd do it but then you're not database-agnostic about it if that matters to you.

Sub Par
Jul 18, 2001


Dinosaur Gum
Either seems like a kludge but I guess the kludge that makes the app more db-agnostic and allows users to potentially change their display name if I decide on that later will win. Thanks for that link though, it's helpful to see how to execute statements like that as part of a migration.

Adbot
ADBOT LOVES YOU

wolffenstein
Aug 2, 2002
 
Pork Pro
Or have them sign in with their email.

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