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
Pardot
Jul 25, 2001




A MIRACLE posted:

Read/Write Purple, Read-only White

Ah, no I meant the type of database mecha, ika, etc. The colors are just randomly assigned on provisioning so that you can have more than one db per app.

Adbot
ADBOT LOVES YOU

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.

sorry it's early for me. they're both "Ika"

KoRMaK
Jul 31, 2012



Is there a way to make a two sided polymorphic join table?

The join table would be:
object_id
object_type
related_item_id
related_item_type

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.

KoRMaK posted:

Is there a way to make a two sided polymorphic join table?

The join table would be:
object_id
object_type
related_item_id
related_item_type

Would be easy enough with custom queries and a manager. Idk if activerecord supports it though.

KoRMaK
Jul 31, 2012



Oh, derp, I can probably get this done with using as: on the object side. I've figured something similar to this out before, it's just a little hazy remembering the nuances of the has many options. The one I always forge is that as defines the column name you want the current object to masquarde as.

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."
Is there a good gem for users to create events and invite people? With security options like public, private, etc?

fantastic in plastic
Jun 15, 2007

The Socialist Workers Party's newspaper proved to be a tough sell to downtown businessmen.
I'm fairly new to Rails and I'm trying to use it to make a web-based wargame. I was building a database to represent all of the countries (board spaces if this were a real game) with columns for each of the things a country has - player1 troops, player2 troops, and so on, with the idea that playing the game would be the machine updating each of those columns as the board state changes.

However, I realized as I started doing it that this would mean the database would be constantly changing, so there couldn't be multiple games. So now I'm thinking that each game would begin with creating a new database "foo" from template "bar" where foo is an automatically sequencing number(ie, game000001, game000002, etc) and bar is the original database. However, this is a little out of my comfort zone and I don't know if that's a good idea or if there's a better way, and Google isn't turning up anything helpful.

Is this a sane way to approach the problem? (Obviously I would need to have the server clean itself up periodically since I don't want scads of completed/zombie game databases laying around.)

kayakyakr
Feb 16, 2004

Kayak is true

Tao Jones posted:

I'm fairly new to Rails and I'm trying to use it to make a web-based wargame. I was building a database to represent all of the countries (board spaces if this were a real game) with columns for each of the things a country has - player1 troops, player2 troops, and so on, with the idea that playing the game would be the machine updating each of those columns as the board state changes.

However, I realized as I started doing it that this would mean the database would be constantly changing, so there couldn't be multiple games. So now I'm thinking that each game would begin with creating a new database "foo" from template "bar" where foo is an automatically sequencing number(ie, game000001, game000002, etc) and bar is the original database. However, this is a little out of my comfort zone and I don't know if that's a good idea or if there's a better way, and Google isn't turning up anything helpful.

Is this a sane way to approach the problem? (Obviously I would need to have the server clean itself up periodically since I don't want scads of completed/zombie game databases laying around.)

That's a horrible way to design this. Horrible.

Create a Game table. Link that to a Competitor table. Have a Pieces or Troops or whatever table that tracks what forces the competitor has and where they are located. Use indexes to keep it all fast.

Game has many competitors
Competitors has many troops
etc etc.


e: Or just do it all in a document database where each game is one whole document which would work if the size was limited. Could do this with postgres and json fields too.

kayakyakr fucked around with this message at 06:55 on May 1, 2014

fantastic in plastic
Jun 15, 2007

The Socialist Workers Party's newspaper proved to be a tough sell to downtown businessmen.

kayakyakr posted:

That's a horrible way to design this. Horrible.

Create a Game table. Link that to a Competitor table. Have a Pieces or Troops or whatever table that tracks what forces the competitor has and where they are located. Use indexes to keep it all fast.

Game has many competitors
Competitors has many troops
etc etc.


e: Or just do it all in a document database where each game is one whole document which would work if the size was limited. Could do this with postgres and json fields too.

Thanks, that's helpful. I got hung up thinking that there should be a Countries table that keeps track of who has what where, but thinking about it in the way you suggest makes a lot of sense.

kayakyakr
Feb 16, 2004

Kayak is true

Tao Jones posted:

Thanks, that's helpful. I got hung up thinking that there should be a Countries table that keeps track of who has what where, but thinking about it in the way you suggest makes a lot of sense.

There could be a countries table, but it'd be linked to the game table and would be linked to by the troops table.

KoRMaK
Jul 31, 2012



I have a custom getter/setter that I want to run through validator using

validates :field, :format => {my_options}

But the statement seems to ignore the validator. Is there a way to bridge the built-in validates feature with my own custom getter/setter?

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

I have a custom getter/setter that I want to run through validator using

validates :field, :format => {my_options}

But the statement seems to ignore the validator. Is there a way to bridge the built-in validates feature with my own custom getter/setter?

validate :my_custom_validation_method

?

fruition
Feb 1, 2014
Took me literally 10 hours to figure out how to clean install Ruby on Rails, Git, and Heroku on Ubuntu. The learning curve apparently starts before you even get your environment setup. There's just too many outdated guides and poo poo, I may be a retard but I feel like it should be easier to setup.

kayakyakr
Feb 16, 2004

Kayak is true

fruition posted:

Took me literally 10 hours to figure out how to clean install Ruby on Rails, Git, and Heroku on Ubuntu. The learning curve apparently starts before you even get your environment setup. There's just too many outdated guides and poo poo, I may be a retard but I feel like it should be easier to setup.

code:
sudo apt-get install git
wget -qO- [url]https://toolbelt.heroku.com/install-ubuntu.sh[/url] | sh
\curl -sSL [url]https://get.rvm.io[/url] | bash -s stable
?

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
http://www.railstutorial.org/

I used this one, it's pretty up to date.

KoRMaK
Jul 31, 2012



fruition posted:

Took me literally 10 hours to figure out how to clean install Ruby on Rails, Git, and Heroku on Ubuntu. The learning curve apparently starts before you even get your environment setup. There's just too many outdated guides and poo poo, I may be a retard but I feel like it should be easier to setup.
If you've never used those tools before, then yea. That's typical for technical skills.

Lexicon
Jul 29, 2003

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

fruition posted:

Took me literally 10 hours to figure out how to clean install Ruby on Rails, Git, and Heroku on Ubuntu. The learning curve apparently starts before you even get your environment setup. There's just too many outdated guides and poo poo, I may be a retard but I feel like it should be easier to setup.

Dude, this is nothing compared to the Java/Struts/Spring/whatever the gently caress else days of yore (uphill both ways, etc).

It probably could be easier, but this is all fairly complex computing machinery.

double sulk
Jul 2, 2010

kayakyakr posted:

code:
sudo apt-get install git
wget -qO- [url]https://toolbelt.heroku.com/install-ubuntu.sh[/url] | sh
\curl -sSL [url]https://get.rvm.io[/url] | bash -s stable
?

rvm is poo poo and you should be using rbenv + ruby-build

kayakyakr
Feb 16, 2004

Kayak is true

double sulk posted:

rvm is poo poo and you should be using rbenv + ruby-build

Serves my purpose and seems to have a shorter setup time than rbenv, so I'll use it until it no longer works for me.

Lexicon
Jul 29, 2003

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

kayakyakr posted:

Serves my purpose and seems to have a shorter setup time than rbenv, so I'll use it until it no longer works for me.

Are you using homebrew? As I recall, rbenv was an absolute breeze to install with that. It really is the better option, but I guess stick with rvm if you must.

double sulk
Jul 2, 2010

kayakyakr posted:

Serves my purpose and seems to have a shorter setup time than rbenv, so I'll use it until it no longer works for me.


Lexicon posted:

Are you using homebrew? As I recall, rbenv was an absolute breeze to install with that. It really is the better option, but I guess stick with rvm if you must.

brew install rbenv ruby-build
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
rbenv install 2.1.1
rbenv global 2.1.1


It's literally four lines on OS X and you can install every version you want and it isn't the gigantic clusterfuck that rvm is.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!
He's on Ubuntu, but that doesn't mean he isn't terribly terribly wrong about his choice of version management. :v:

fruition
Feb 1, 2014

Gmaz posted:

http://www.railstutorial.org/

I used this one, it's pretty up to date.

Yeah this is what I used to get a working setup. I must say I'm liking Rails so far :D and it's great to have a reason to learn Linux finally.

KoRMaK
Jul 31, 2012



In a view, I'm doing some caching

Ruby code:
<% cache ['my_view', obj] do %>
Problem is, when obj is a custom class I wrote I get nil exception errors. Another custom class I wrote works fine, but this one in particular does not. I added a cache_key method to my custom object, and it doesn't ever get hit. What am I missing?

xtal
Jan 9, 2011

by Fluffdaddy

Lexicon posted:

Dude, this is nothing compared to the Java/Struts/Spring/whatever the gently caress else days of yore (uphill both ways, etc).

It probably could be easier, but this is all fairly complex computing machinery.

I don't think that's fair, I set up Java for development in 15 minutes and 10 of it was downloading packages because I haven't ever had anything Java on my computer. It's not hard to set up a development environment in either language anymore.

Lexicon
Jul 29, 2003

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

xtal posted:

I don't think that's fair, I set up Java for development in 15 minutes and 10 of it was downloading packages because I haven't ever had anything Java on my computer. It's not hard to set up a development environment in either language anymore.

Yeah, I haven't touched Java in about half a decade so I'm not surprised that isn't accurate. Respectfully withdrawn :)

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.
I feel like I should know the answer to this, but apparently don't: is it possible to rely exclusively on 'bundler' for gem installation? I'm about to start using middleman for static site generation, and all the tutorials are requiring that I 'gem install middleman' first, despite referencing bundler later. Can I not just structure things so only bundler installs the gem? Or is that not feasible because the 'middleman' command needs to be available in the terminal?

KoRMaK
Jul 31, 2012



KoRMaK posted:

In a view, I'm doing some caching

Ruby code:
<% cache ['my_view', obj] do %>
Problem is, when obj is a custom class I wrote I get nil exception errors. Another custom class I wrote works fine, but this one in particular does not. I added a cache_key method to my custom object, and it doesn't ever get hit. What am I missing?
I did some more tracking on this, and the cache_key is being ran on the containing hash (obj is a hash). I dived into the rails library and found out that it is going wrong somewhere with calling hash.to_param. Being able to go into rails source code and just put debugger statements helps so much :aaa:

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Lexicon posted:

I feel like I should know the answer to this, but apparently don't: is it possible to rely exclusively on 'bundler' for gem installation? I'm about to start using middleman for static site generation, and all the tutorials are requiring that I 'gem install middleman' first, despite referencing bundler later. Can I not just structure things so only bundler installs the gem? Or is that not feasible because the 'middleman' command needs to be available in the terminal?

Yes, you can just let bundler handle all the gem installation. The only downside is that you might have to preface your middleman calls with "bundle exec".

Bundler doesn't strictly sandbox gems like using gemsets, or python's virtualenv. Think of it as a filter on the larger pool of gems that you have installed, making sure that only the ones you've specified are activated.

Lexicon
Jul 29, 2003

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

Sailor_Spoon posted:

Yes, you can just let bundler handle all the gem installation. The only downside is that you might have to preface your middleman calls with "bundle exec".

Bundler doesn't strictly sandbox gems like using gemsets, or python's virtualenv. Think of it as a filter on the larger pool of gems that you have installed, making sure that only the ones you've specified are activated.

Perfect - thanks. This worked beautifully.

xtal
Jan 9, 2011

by Fluffdaddy

Sailor_Spoon posted:

Yes, you can just let bundler handle all the gem installation. The only downside is that you might have to preface your middleman calls with "bundle exec".

Bundler doesn't strictly sandbox gems like using gemsets, or python's virtualenv. Think of it as a filter on the larger pool of gems that you have installed, making sure that only the ones you've specified are activated.

If you use binstubs, you won't need to use bundle exec. And if you use the --path option, you can install them in your vendor/ruby (or any other) folder and not globally. The only non-default gem I have installed globally is bundler.

Sil
Jan 4, 2007
I'm reading about Vagrant and in their docs they do

code:
$script = <<SCRIPT
echo I am provisioning...
date > /etc/vagrant_provisioned_at
SCRIPT
to define a multiline string. Is this just syntactic sugar for the,"""string with preserved newlines""", triple double quotes?

OK, never mind I tracked it down via google. It's just a different type of string literal. For some reason searcing ruby-doc.org for << doesn't find anything.

xtal
Jan 9, 2011

by Fluffdaddy

Sil posted:

I'm reading about Vagrant and in their docs they do

code:
$script = <<SCRIPT
echo I am provisioning...
date > /etc/vagrant_provisioned_at
SCRIPT
to define a multiline string. Is this just syntactic sugar for the,"""string with preserved newlines""", triple double quotes?

OK, never mind I tracked it down via google. It's just a different type of string literal. For some reason searcing ruby-doc.org for << doesn't find anything.

Ruby doesn't have triple-quote literals in the sense that Python does. It just concatenates two adjacent string literals together implicitly. """something"""" is just "" + "something" + "".

Jaded Burnout
Jul 10, 2004


Sil posted:

I'm reading about Vagrant and in their docs they do

code:
$script = <<SCRIPT
echo I am provisioning...
date > /etc/vagrant_provisioned_at
SCRIPT
to define a multiline string. Is this just syntactic sugar for the,"""string with preserved newlines""", triple double quotes?

OK, never mind I tracked it down via google. It's just a different type of string literal. For some reason searcing ruby-doc.org for << doesn't find anything.

It's called a HEREDOC. It's a Perl thing.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.

Arachnamus posted:

It's called a HEREDOC. It's a Perl thing.

sh thing originally. :eng101:

Jaded Burnout
Jul 10, 2004


Smol posted:

sh thing originally. :eng101:

I know :) But let's be honest it's a Perl thing, like so many of the dark corners of Ruby (like all that horrible File shite).

Sil
Jan 4, 2007

Arachnamus posted:

It's called a HEREDOC. It's a Perl thing.

Yeah I read a bit of that link I added and then stopped when I saw that it goes. On. For. Pages. It's like an entire DSL tied to one freaking operator :D

Wait. Where did I pick up that """ """ thing? It must have been some rails tutorial book, but I could have sworn they said that's the way to do multiline strings in ruby. I see now, in IRB, that regular string literals do that just fine.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Can anyone help me with nested forms?

I have a user model (generated by devise with some additional attributes) that has and belongs to many languages. They have their join table in the schema and everything works correctly in that regard.

But how do I create a view that will allow the person to edit the user model and at the same time pick a number of languages (via checkbox) the user knows from the form?

Basically I want there to be a checkbox for every language and then the user checks which one he/she knows after which associations will be created between that user and the languages. Problem is I have no idea where to even start with this, since I'm a rails newbie. I tried some stuff like collection_boxes and form nesting but to no avail. Can somebody at least point me in the direction of what I should be looking for?

Here is the current view which edits the user model, I'd like to add the checkboxes here.

Gmaz fucked around with this message at 13:14 on May 8, 2014

Sil
Jan 4, 2007
Any resources on figuring out what app/web server to use?

I've been using Unicorn on Heroku and it works fine. I'm looking into experimenting with AWS micro instances and my current plan is to use Nginx and Unicorn. Unfortunately, I haven't been able to find decent benchmarks for when to use which app server.

For instance, there are a number of tiny traffic apps that I was thinking of deploying on a single micro instance. Would something like Phusion Passenger make more sense in a situation like this? I ask because I'm reading that Phusio can handle multiple apps out of the box, whereas with Unicorn I'd need to start a new Unicorn master process for each app, as far as I understand.

Adbot
ADBOT LOVES YOU

Jaded Burnout
Jul 10, 2004


Sil posted:

Wait. Where did I pick up that """ """ thing? It must have been some rails tutorial book, but I could have sworn they said that's the way to do multiline strings in ruby. I see now, in IRB, that regular string literals do that just fine.

Not sure. It's common in Cucumber, maybe from there?

I'm not a fan of it myself, but they're all fairly horrible options when you've got to keep strict whitespace formatting in your multiline string. Not sure whether """ does anything special.

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