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
Oh My Science
Dec 29, 2008
I think you're looking for something like https://github.com/norman/friendly_id

Treehouse has a tutorial on how you can do it yourself http://blog.teamtreehouse.com/creating-vanity-urls-in-rails

Adbot
ADBOT LOVES YOU

prom candy
Dec 16, 2005

Only I may dance
Just use the friendly_id gem, it's quick and awesome.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
So a lot of you guys probably use apache or nginx on a relatively up-to-date distro. If you're using TLS as well, you better upgrade your packages, because a pretty big hole was found from openssl 1.0.1.

http://www.openssl.org/news/secadv_20140407.txt

Here's an online tool that you can use to see if you're vulnerable:

http://filippo.io/Heartbleed/

Short checklist if you were affected (by no means comprehensive):

- Update your system and make sure you're not vulnerable any more
- Get new certificates
- Regenerate a new Rails session secret to invalidate existing user sessions
- Change any passwords or other potentially compromising information that might've passed through apache/nginx.

On a side note, being still on RHEL 6 or Debian 6 mostly saved our asses at work. :sweatdrop:

Smol fucked around with this message at 20:55 on Apr 8, 2014

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Smol posted:

So a lot of you guys probably use apache or nginx on a relatively up-to-date distro. If you're using TLS as well, you better upgrade your packages, because a pretty big hole was found from openssl 1.0.1.

http://www.openssl.org/news/secadv_20140407.txt

Here's an online tool that you can use to see if you're vulnerable:

http://filippo.io/Heartbleed/

Short checklist if you were affected (by no means comprehensive):

- Update your system and make sure you're not vulnerable any more
- Get new certificates
- Regenerate a new Rails session secret to invalidate existing user sessions
- Change any passwords or other potentially compromising information that might've passed through apache/nginx.

On a side note, being still on RHEL 6 or Debian 6 mostly saved our asses at work. :sweatdrop:
Do note that RHEL 6.5 is vulnerable (though prior versions are not).

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.

Misogynist posted:

Do note that RHEL 6.5 is vulnerable (though prior versions are not).

That's true. Also certain extensions (like mod_spdy for apache) might include a newer, vulnerable version of openssl, making you vulnerable even if your distro still uses openssl 0.9.8.

Smol fucked around with this message at 23:55 on Apr 8, 2014

kayakyakr
Feb 16, 2004

Kayak is true
thanks for the heads up. most of my servers were vulnerable, especially since I had been using ubuntu 13.04 for dokku compatibility (docker had a bug in 13.10 that they just recently fixed).

no_funeral
Jul 4, 2004

why
Rails 4/Mongoid 4 question:

Is it possible to setup a scope which will query a referenced array of IDs, providing it either a singular ID OR an array of IDs, or will I need to make it into two scopes?

Now that I've been away from my dev station for an hour, I'm thinking I can do it with one scope, and I was just passing the array improperly(would need to be a hash with the name of the referenced ID as the key for all of the values passed)

For context, this is for filtering within calls to an API I'm building.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Sitting Bull posted:

Rails 4/Mongoid 4 question:

Is it possible to setup a scope which will query a referenced array of IDs, providing it either a singular ID OR an array of IDs, or will I need to make it into two scopes?

Now that I've been away from my dev station for an hour, I'm thinking I can do it with one scope, and I was just passing the array improperly(would need to be a hash with the name of the referenced ID as the key for all of the values passed)

For context, this is for filtering within calls to an API I'm building.

If you're just trying to meet the requirement of "I can pass an individual ID, or an array of ids", .where supports that out of the box:

code:
  self.by_id(ids)
    where(id: ids)
  end
If ids is an array, it will do a IN query on the database, if it's a FixNum it will just do an equality check.

no_funeral
Jul 4, 2004

why

enki42 posted:

If you're just trying to meet the requirement of "I can pass an individual ID, or an array of ids", .where supports that out of the box:

code:
  self.by_id(ids)
    where(id: ids)
  end
If ids is an array, it will do a IN query on the database, if it's a FixNum it will just do an equality check.

Thank you! This will do just fine. The whole thing was because I was building a query in the controller, and somebody said that I'd need to move it into a combination of scopes in the model to test it properly with RSpec, which this will satisfy.

Sil
Jan 4, 2007
Weird Ruby 2.1 gets problem: I'm using zsh on Mac OS X, and gets doesn't recognize the return character. Whenever I run a script it enters the gets mode, I type in inputs, but whenever I press enter it just echoes ^M at me instead of returning from gets. Extra weird: running gets in the pry repl works just fine. Do I need to tell ruby how to handle Mac line endings?

Jaded Burnout
Jul 10, 2004


Sil posted:

Weird Ruby 2.1 gets problem: I'm using zsh on Mac OS X, and gets doesn't recognize the return character. Whenever I run a script it enters the gets mode, I type in inputs, but whenever I press enter it just echoes ^M at me instead of returning from gets. Extra weird: running gets in the pry repl works just fine. Do I need to tell ruby how to handle Mac line endings?

code:
$ zsh
% irb
2.1.1 :001 > gets
test
 => "test\n" 
2.1.1 :002 >
Seems to work OK. Your version of readline maybe?

Edit: Testing in a script:
code:
string = gets
puts string
code:
$ ruby echo.rb 
test
test

Jaded Burnout fucked around with this message at 15:02 on Apr 11, 2014

Sil
Jan 4, 2007

Arachnamus posted:

code:
$ zsh
% irb
2.1.1 :001 > gets
test
 => "test\n" 
2.1.1 :002 >
Seems to work OK. Your version of readline maybe?

Edit: Testing in a script:
code:
string = gets
puts string
code:
$ ruby echo.rb 
test
test

Fixed itselfish.

I updated zsh in a different terminal tab and then didn't restart the one I ended up using to run the script. Just tried the script now in a new terminal session and it works fine. Weird stuff. The old tab has a red X and a gear symbol at the start of the graphical prompt that should have clued me in that things were not kosher.

Finally realized that I need to close the old terminal tab when I tried typing in a sudo password and enter didn't work there either.

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013
Didn't know FriendlyId was a thing that existed. Neat.

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.

Soooo is the Heroku sendgrid addon always going to get spam-filtered? Is there any way around this without going directly to sendgrid?

Pardot
Jul 25, 2001




I just added the addon and did `heroku addons:open sendgrid` and poked around their settings, and it looks like there are some DKIM options. I don't use them myself though so I'm not sure what to expect there.

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.

Mmm, I checked that out and it just rewrites the sender domain name. I think the issue is that Gmail thinks the IP range (heroku's?) for the sender is wack

edit: Looks like Gold customers get their own dedicated IP? Sendgrid FAQ is saying there's a 'warming up' period for new IPs before ISPs have determined that you're worthy of not being flagged as spam

A MIRACLE fucked around with this message at 22:20 on Apr 14, 2014

Sil
Jan 4, 2007

A MIRACLE posted:

Mmm, I checked that out and it just rewrites the sender domain name. I think the issue is that Gmail thinks the IP range (heroku's?) for the sender is wack

edit: Looks like Gold customers get their own dedicated IP? Sendgrid FAQ is saying there's a 'warming up' period for new IPs before ISPs have determined that you're worthy of not being flagged as spam

I use Sendgrid free tier and none of my emails get marked as spam. This is small volume stuff to a set list of a few hundred recipients, though. After the first few thousand emails you should be fine. Make sure you are linking your domain to the emails and that your from/domain info match up.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Sil posted:

I use Sendgrid free tier and none of my emails get marked as spam. This is small volume stuff to a set list of a few hundred recipients, though. After the first few thousand emails you should be fine. Make sure you are linking your domain to the emails and that your from/domain info match up.

Also set up SPF and DKIM. If you've set up SPF for Google apps or some other email provider, you also have to add an entry for SendGrid.

kayakyakr
Feb 16, 2004

Kayak is true
Just checking to make sure I haven't missed something that's come out in the last few years, I want to be able to do something like:

Ruby code:
  class Entry
    include Mongoid::Document

    belongs_to :association

    def self.sorted
      # some custom sorting algorithm that would be run 
      # at the end of an query chain
    end
  end

  Entry.where(association_id: '').sorted
But I do not believe that this is possible in any way. I have a sort that is more complex than mongo can handle and need to do it in ruby (should be O(n), thankfully, just a 2-step sort), but I was hoping to find some implementation that was a bit cleaner.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

kayakyakr posted:

Just checking to make sure I haven't missed something that's come out in the last few years, I want to be able to do something like:

Ruby code:
  class Entry
    include Mongoid::Document

    belongs_to :association

    def self.sorted
      # some custom sorting algorithm that would be run 
      # at the end of an query chain
    end
  end

  Entry.where(association_id: '').sorted
But I do not believe that this is possible in any way. I have a sort that is more complex than mongo can handle and need to do it in ruby (should be O(n), thankfully, just a 2-step sort), but I was hoping to find some implementation that was a bit cleaner.

If you can turn a document into a single sort key, you can use Array#sort_by to sort on that key: http://rdoc.info/stdlib/core/Enumerable:sort_by

The caveats about lexicographic sorting with strings vs. numeric sorting with numbers apply.

kayakyakr
Feb 16, 2004

Kayak is true

Cocoa Crispies posted:

If you can turn a document into a single sort key, you can use Array#sort_by to sort on that key: http://rdoc.info/stdlib/core/Enumerable:sort_by

The caveats about lexicographic sorting with strings vs. numeric sorting with numbers apply.

nope, can't be reduced in that way.

Talked it over with Journey and it may need to be a gem, down the road, that gives a callback spot right before the values are returned.

prom candy
Dec 16, 2005

Only I may dance
We have a WYSIWYG editor that we've built that splits content up into Rows and Pieces which are classified as RowTypes and PieceTypes. Basically it lets a user build a page by adding rows like "Two Columns of Text" or "An image with text wrapped around it" or "an embed code" or whatever, here I'll just post some screenshots so you can see what I mean:





Okay so this, as you can imagine, is all done via associations, child relationships, nested attributes, and some considerable finagling of the excellent cocoon gem. It's all working fairly well and people seem to like it, but now we have a new requirement: we need to be able to safe draft versions, track some level of revision history, and allow reversions to previous versions of items that are built with this content (this editor is part of a larger CMS and it can be attached to any number of models). poo poo.

I've looked into paper_trail and it doesn't look like it has a lot of support for saving a big cascade of nested models. I'm not against coding something up from scratch but I feel like someone must have solved this problem before. Does anyone have any suggestions for where to begin on something like this?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

prom candy posted:

We have a WYSIWYG editor that we've built that splits content up into Rows and Pieces which are classified as RowTypes and PieceTypes. Basically it lets a user build a page by adding rows like "Two Columns of Text" or "An image with text wrapped around it" or "an embed code" or whatever, here I'll just post some screenshots so you can see what I mean:





Okay so this, as you can imagine, is all done via associations, child relationships, nested attributes, and some considerable finagling of the excellent cocoon gem. It's all working fairly well and people seem to like it, but now we have a new requirement: we need to be able to safe draft versions, track some level of revision history, and allow reversions to previous versions of items that are built with this content (this editor is part of a larger CMS and it can be attached to any number of models). poo poo.

I've looked into paper_trail and it doesn't look like it has a lot of support for saving a big cascade of nested models. I'm not against coding something up from scratch but I feel like someone must have solved this problem before. Does anyone have any suggestions for where to begin on something like this?

Welcome to my nightmares; I was the sole competent developer on a Rails CMS like this back in '08. The blasé answer is to polish up your resume.

Review my assumptions: a Page is made of a bunch of Rows and Pieces, and a given row or piece belongs to one page and one page only. RowTypes and PieceTypes are shared between pages and don't really factor in to this discussion. You want to version a page, including its component rows and pieces.

I'd probably look at denormalizing rows and pieces into a single field on a PageRevision, and keeping it either in a Postgres hstore or json column, or maybe a blob column.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Tree structures, versioning & SQL. Sounds like you want closure tables if you want to keep it normalized.


http://www.slideshare.net/billkarwin/models-for-hierarchical-data

Smol fucked around with this message at 01:09 on Apr 17, 2014

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

prom candy posted:

We have a WYSIWYG editor that we've built that splits content up into Rows and Pieces which are classified as RowTypes and PieceTypes. Basically it lets a user build a page by adding rows like "Two Columns of Text" or "An image with text wrapped around it" or "an embed code" or whatever, here I'll just post some screenshots so you can see what I mean:





Okay so this, as you can imagine, is all done via associations, child relationships, nested attributes, and some considerable finagling of the excellent cocoon gem. It's all working fairly well and people seem to like it, but now we have a new requirement: we need to be able to safe draft versions, track some level of revision history, and allow reversions to previous versions of items that are built with this content (this editor is part of a larger CMS and it can be attached to any number of models). poo poo.

I've looked into paper_trail and it doesn't look like it has a lot of support for saving a big cascade of nested models. I'm not against coding something up from scratch but I feel like someone must have solved this problem before. Does anyone have any suggestions for where to begin on something like this?

Sounds pretty similar to something I had to build this year (various parent models have a series of various kinds of content chunks). Thankfully I don't forsee needing this level of revision history for our purposes but I'm interested to see what kinds of solutions exist.

KoRMaK
Jul 31, 2012



Has anyone had experience with CanCan? I have class_b which has a relationship to class_a. I want the load_and_authorize_resource call that cancan provides to authorize class_b's actions based on it's relationship to class_a. The documentation for cancan isn't clear about this, and I've tried the :parent and :through methods but it doesn't seem to be right.

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

Has anyone had experience with CanCan? I have class_b which has a relationship to class_a. I want the load_and_authorize_resource call that cancan provides to authorize class_b's actions based on it's relationship to class_a. The documentation for cancan isn't clear about this, and I've tried the :parent and :through methods but it doesn't seem to be right.

1) You should switch to CanCanCan as soon as you are able. CanCan has been abandoned by the creator and taken over by a group of others

2) I don't think you can rely on cancan's auto-load to do that. You might be able to build up a finder that can find the correct authorized classes and that would work.

I would suggest going ahead and loading the resources in a before_action/filter, then calling authorize_resource (layer them in your class so you have:

Ruby code:
class MyClass
  before_action :load_resource
  authorize_resource

  def load_resource
  end
end
In ability.rb, then, you can determine authorization in a block.

KoRMaK
Jul 31, 2012



kayakyakr posted:

1) You should switch to CanCanCan as soon as you are able. CanCan has been abandoned by the creator and taken over by a group of others

2) I don't think you can rely on cancan's auto-load to do that. You might be able to build up a finder that can find the correct authorized classes and that would work.

I would suggest going ahead and loading the resources in a before_action/filter, then calling authorize_resource (layer them in your class so you have:

Ruby code:
class MyClass
  before_action :load_resource
  authorize_resource

  def load_resource
  end
end
In ability.rb, then, you can determine authorization in a block.

poo poo, I had overridden find_resource instead.

KoRMaK fucked around with this message at 18:46 on Apr 17, 2014

KoRMaK
Jul 31, 2012



Here's a more general question, how do I override a method that is used as a prepend_filter?

Instead of doing before_action :load_resource, I'd rather just override the load_resource method from cancan
https://github.com/ryanb/cancan/blob/master/lib/cancan/controller_resource.rb#L29

When I define the method in my controller, it doesn't ever get called. Why is that?

prom candy
Dec 16, 2005

Only I may dance

Smol posted:

Tree structures, versioning & SQL. Sounds like you want closure tables if you want to keep it normalized.


http://www.slideshare.net/billkarwin/models-for-hierarchical-data

Oh god I'm going to have to learn a whole bunch of stuff to do this right aren't I?

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.

prom candy posted:

Oh god I'm going to have to learn a whole bunch of stuff to do this right aren't I?

The classic book on the subject:

http://www.cs.arizona.edu/~rts/tdbbook.pdf

KoRMaK
Jul 31, 2012



kayakyakr posted:

1) You should switch to CanCanCan as soon as you are able. CanCan has been abandoned by the creator and taken over by a group of others

2) I don't think you can rely on cancan's auto-load to do that. You might be able to build up a finder that can find the correct authorized classes and that would work.

I would suggest going ahead and loading the resources in a before_action/filter, then calling authorize_resource (layer them in your class so you have:

Ruby code:
class MyClass
  before_action :load_resource
  authorize_resource

  def load_resource
  end
end
In ability.rb, then, you can determine authorization in a block.

I did the above, and it doesn't seem to work. Can you explain what the flow should be?

Like, how do I get cancan to use the class_a that I loaded to do authing?

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

I did the above, and it doesn't seem to work. Can you explain what the flow should be?

Like, how do I get cancan to use the class_a that I loaded to do authing?

authorize_resource checks for an instance variable of the same name as the class. for MyClass it's looking for @my_class or @my_classes (on index) to authorize.

You can override that with
Ruby code:
authorize_resource :my_instance
Also, according to https://github.com/CanCanCommunity/cancancan/wiki/Nested-Resources you can define nested resources as above. Your mileage may vary if you haven't already tried that.

As a reminder, cancan is not compatible with rails 4. most of it works, but some of it is very broken, especially when dealing with relations and how it does its lookups. CanCanCan rectifies some of that breakage.

KoRMaK
Jul 31, 2012



kayakyakr posted:

authorize_resource checks for an instance variable of the same name as the class. for MyClass it's looking for @my_class or @my_classes (on index) to authorize.

You can override that with
Ruby code:
authorize_resource :my_instance
Also, according to https://github.com/CanCanCommunity/cancancan/wiki/Nested-Resources you can define nested resources as above. Your mileage may vary if you haven't already tried that.

As a reminder, cancan is not compatible with rails 4. most of it works, but some of it is very broken, especially when dealing with relations and how it does its lookups. CanCanCan rectifies some of that breakage.
Thank you. I've taken to going through the gem's lib and found this which backs up what you are saying https://github.com/ryanb/cancan/blob/master/lib/cancan/controller_additions.rb#L145

Oh My Science
Dec 29, 2008
https://github.com/elabs/pundit is the new authorization kid on the block if you want to give it a shot.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

Oh My Science posted:

https://github.com/elabs/pundit is the new authorization kid on the block if you want to give it a shot.

This actually looks pretty fantastic- I might try to use it in some of my stuff at work.

KoRMaK
Jul 31, 2012



Wow, I just had a small error result in hours of confusion and lost work time.

"Hash.key(:my_key)" is not the same as :Hash.key?(:my_key)"

I knew this, I utilize both a bunch. I just overlooked the "?"

It's kind of nice to feel so young and stupid again.


(the load_resource solution kayakyakr suggested would have worked immediately if I hadn't made that mistake.)

prom candy
Dec 16, 2005

Only I may dance

Thanks! I've been trying to fill some of the gaps in my knowledge, database design is a huge one for me.

Slow News Day
Jul 4, 2007

I've been wrestling with Mercury Editor. Finally got it to work in my development environment, but when I pushed it to Heroku I ran into a problem that I struggled with all day today. I have the write-up here. Anyone have thoughts?

The lovely thing is that Mercury's developer seems to have stopped working on it. Which is a shame, since it's pretty awesome. I haven't found anything that integrates so seamlessly with Rails.

Adbot
ADBOT LOVES YOU

hmm yes
Dec 2, 2000
College Slice
We went through the exact same thing with Mercury editor. We gave up on it and switched to CK Editor using inline mode, and it has been great. Transition wasn't very difficult. We added an internal policy against using gems/libraries with less than 10 contributors on github because we've been burned a few times by solo projects like Mercury editor.

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