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
kayakyakr
Feb 16, 2004

Kayak is true

8ender posted:

We user bower to grab our JS libs and chuck them into the asset pipeline before it hits docker. Works well.

Bower is the worst.

Adbot
ADBOT LOVES YOU

Huzanko
Aug 4, 2015

by FactsAreUseless

kayakyakr posted:

Bower is the worst.

I keep hearing this but I don't understand why. I also hear NPM is pretty poo poo as well. Nothing is good; everything is terrible.

8ender
Sep 24, 2003

clown is watching you sleep
Bower has been working fine for us? It's an extra step in the docker image build process but after that we just reference everything we need in application.js and everything works.

Removing a billions lines of lib JS from our app was lovely.

Pollyanna
Mar 5, 2005

Milk's on them.


I'm going the Rails 5 API route for the new project and it's working out beautifully. I'm a fan.

Huzanko
Aug 4, 2015

by FactsAreUseless

Pollyanna posted:

I'm going the Rails 5 API route for the new project and it's working out beautifully. I'm a fan.

Same. I am really liking that they added the "--api" flag to "rails new." And rack-cors is in the Gemfile by default!

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Noam Chomsky posted:

I keep hearing this but I don't understand why. I also hear NPM is pretty poo poo as well. Nothing is good; everything is terrible.

Bower completely wraps something like a Gemfile.lock, so you have to be restrictive in your versioning. It also uses Github + tagging instead of a real release process. There's nothing centralized, so if someone unpublishes a module you're hosed.

NPM has the shrinkwrap command, which handles versioning. And it has at least something along the lines of a release process, in that you have to explicitly package it. They also have a central repo so that they can handle children throwing hissy fits.

Most of the problem comes from the mindset of JS devs. But at least NPM has a few things in place to handle that.

Huzanko
Aug 4, 2015

by FactsAreUseless

EVGA Longoria posted:

Bower completely wraps something like a Gemfile.lock, so you have to be restrictive in your versioning. It also uses Github + tagging instead of a real release process. There's nothing centralized, so if someone unpublishes a module you're hosed.

NPM has the shrinkwrap command, which handles versioning. And it has at least something along the lines of a release process, in that you have to explicitly package it. They also have a central repo so that they can handle children throwing hissy fits.

Most of the problem comes from the mindset of JS devs. But at least NPM has a few things in place to handle that.

Don't get me wrong, I like NPM, it's just that the hatred and derision of Bower seems kind of silly to me, especially since NPM has its issues too - http://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/ apropos of the bolded.

Bower always seemed to me to be this neat little front-end assets package manager that's dead simple. I don't get the "BOWER MUST DIE! MUHAHAH!"

WRT Rails, I prefer just using gems.

Huzanko fucked around with this message at 21:28 on Jun 14, 2016

KoRMaK
Jul 31, 2012



Does anyone know how to interactively get a debugger working for node/grunt/express? I get as far as the initial inspector opening the grunt file but it never hits any breakpoints after that.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Noam Chomsky posted:

Don't get me wrong, I like NPM, it's just that the hatred and derision of Bower seems kind of silly to me, especially since NPM has its issues too - http://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/ apropos of the bolded.

Bower always seemed to me to be this neat little front-end assets package manager that's dead simple. I don't get the "BOWER MUST DIE! MUHAHAH!"

WRT Rails, I prefer just using gems.

What you linked is what I meant. Here's the difference though:

On NPM, the admins republished the module. On bower, that can't happen and you have just completely broken bower.

I had bower destroy my setup twice as often as NPM, despite using bower for <6 months and NPM for over a year.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!
Am I the only person left in TYOOL 2016 that manually adds every JS library that he uses? Granted, I don't use much, but still.

The Journey Fraternity fucked around with this message at 05:37 on Jun 15, 2016

kayakyakr
Feb 16, 2004

Kayak is true

The Journey Fraternity posted:

Am I the only person left in TYOOL 2016 that manually adds every JS library that he uses? Granted, I don't use much, but still.

*deckard cain voice*

back in my day we didn't have all this fancy gem files. Everything was a plugin and svn submodule.

Huzanko
Aug 4, 2015

by FactsAreUseless
Does anyone have any recommendations for gems or methods to handle authentication between an Angular app on one server and a Rails API on another?

Every Ruby gem and Angular module I try seems to have a bunch of open issues and/or is no longer actively maintained - https://github.com/cloudspace/angular_devise, https://github.com/lynndylanhurley/ng-token-auth, https://github.com/lynndylanhurley/devise_token_auth

I tried getting devise_token_auth and ng-token-auth working and I ended up with sign in working and sign up working and then sign out wouldn't work and it kept saying there was no logged in user. For something that is becoming a common requirement you'd think there'd be more and better solutions out there.

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat

The Journey Fraternity posted:

Am I the only person left in TYOOL 2016 that manually adds every JS library that he uses? Granted, I don't use much, but still.

I never use bullshit like bower or npm and I get along just fine. If a library requires me to use either of those abominations I use something else because chances are the author is an idiot.

Anveo
Mar 23, 2002
I think the approach react_on_rails takes is pretty nice template for anyone who wants to sprinkle in some modern JS (npm, es2016, webpack, react, redux, etc) into a Rails app where appropriate.

Basically you put all the fancy JS stuff (package.json, webpack.config, babel, etc) in a new directory (/client) and create webpack build tasks and file watchers. Then adjust the asset pipeline path to pickup the webpack output.

For me it's the best of all worlds:

  1. Everything is in a single repo
  2. 90% of the time I use a normal Rails workflow which I find insanely productive
  3. if I want some modern JS stuff, I can use npm to manage those deps
  4. it works great with turbolinks so the entire site feels like a SPA without actually having to write *everything* in JS (I started using turbolinks5 and it seems pretty ok now)
  5. hot reloading of react components works fine
  6. react_on_rails provides some helpers to render the components on the server
  7. I don't necessarily need to run both Rails app servers and Node app servers

For example, I have a fairly advanced form which filters some data. There are multiple areas of the form all over the page, and separate hidden ones designed for mobile. It's nice to use react/redux to have a single state object which re-renders all those areas quickly and easily. When a user modifies one of the filter items, I don't even use react to process the new results. I just use turbolinks and submit the form like normal. This way I'm still writing the results data in an ERB template, taking advantage of Rails caching and any other ruby libraries I want to use.

I don't know much about Ember, but people say it integrates nicely so maybe they have a similar approach?

kayakyakr
Feb 16, 2004

Kayak is true

Anveo posted:

I think the approach react_on_rails takes is pretty nice template for anyone who wants to sprinkle in some modern JS (npm, es2016, webpack, react, redux, etc) into a Rails app where appropriate.

Basically you put all the fancy JS stuff (package.json, webpack.config, babel, etc) in a new directory (/client) and create webpack build tasks and file watchers. Then adjust the asset pipeline path to pickup the webpack output.

For me it's the best of all worlds:

  1. Everything is in a single repo
  2. 90% of the time I use a normal Rails workflow which I find insanely productive
  3. if I want some modern JS stuff, I can use npm to manage those deps
  4. it works great with turbolinks so the entire site feels like a SPA without actually having to write *everything* in JS (I started using turbolinks5 and it seems pretty ok now)
  5. hot reloading of react components works fine
  6. react_on_rails provides some helpers to render the components on the server
  7. I don't necessarily need to run both Rails app servers and Node app servers

For example, I have a fairly advanced form which filters some data. There are multiple areas of the form all over the page, and separate hidden ones designed for mobile. It's nice to use react/redux to have a single state object which re-renders all those areas quickly and easily. When a user modifies one of the filter items, I don't even use react to process the new results. I just use turbolinks and submit the form like normal. This way I'm still writing the results data in an ERB template, taking advantage of Rails caching and any other ruby libraries I want to use.

I don't know much about Ember, but people say it integrates nicely so maybe they have a similar approach?

Ember has https://github.com/thoughtbot/ember-cli-rails and it's 100% better than react_on_rails.

I have a few major problems with react_on_rails:

1) It just drops its compiled files into an assets directory. Needs to be using /tmp/cache like ember-cli-rails and browserify do.
2) It requires you use a separate executable through an npm script to start the rails server and webpack watcher. Needs to work through just rails s.
3) It's got a double nested layer of npm, one in the webpack project and one outside. Should be using rake, if anything, outside of the webpack directory instead of npm scripts.

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".
Very interesting talk about all that SPA things I seem to be way too far behind, drat!

On a diverging matter, any of you guys use solr / elasticsearch ? Is it worth the hassle for a small-ish application ? I'm thinking it might be nicer to use for a search form on one of the application I've developed but I'm not quite sure if it's worth the hassle.

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

xenilk posted:

Very interesting talk about all that SPA things I seem to be way too far behind, drat!

On a diverging matter, any of you guys use solr / elasticsearch ? Is it worth the hassle for a small-ish application ? I'm thinking it might be nicer to use for a search form on one of the application I've developed but I'm not quite sure if it's worth the hassle.

I'd use sphinx for something smaller.

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".

necrotic posted:

I'd use sphinx for something smaller.

oh wow, thanks a lot that's neat, never heard of it but seems to fit my needs perfectly :)

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
If it's a small number of records and you're using Postgres, look into the pg_search gem. Elasticsearch is pretty awesome but only at the scale where offloading search makes sense.

And +1 for ember-cli-rails

Peristalsis
Apr 5, 2004
Move along.
I have to get up to speed with a Rails 4 app using the Grape gem, and I'm getting confused about how to use it.

I've been reading http://www.thegreatcodeadventure.com/making-a-rails-api-with-grap/, the github page(s), and rails documentation to figure it out.

My first issue is mounting. I think I kind of understand what the mount keyword in routes.rb does, but then the first link above shows this code...

code:
module API  
  class Base < Grape::API
    mount API::V1::Base
  end
end  
and gives this explanation:

"The mount keyword tells your Rails app that another application (usually a rack application and this case our Grape API) exists at that location. Mounting a rack app here means that the functionality of that app/code base is now available inside our Rails application."

I'm not sure how to parse that sentence, or that code.
  • Is this mount command a way of announcing to rails that, within this application, this class is what 'API::V1::Base' should refer to, or is it saying that this class is a wrapper for something at API::V1::Base?
  • All the references I can find for mount within rails talk about mounting from within routes.rb. Is this the same command as the routes mounting, or is this mount different in some way?

I'll probably have more questions once I get farther along.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Yeah, mount in that spot looks odd to me, too. However, further down they have you mount API::Base in the routes file. So I think what's happening here is "nested applications" in essence: the API::Base in routes handles initial matching of routes, and then uses the apps mounted under that class for further matching and eventual execution.

edit: Yeah, Grape::DSL::API defines mount: https://github.com/ruby-grape/grape/blob/master/lib/grape/dsl/routing.rb#L80

Peristalsis
Apr 5, 2004
Move along.

necrotic posted:

Yeah, mount in that spot looks odd to me, too. However, further down they have you mount API::Base in the routes file. So I think what's happening here is "nested applications" in essence: the API::Base in routes handles initial matching of routes, and then uses the apps mounted under that class for further matching and eventual execution.

edit: Yeah, Grape::DSL::API defines mount: https://github.com/ruby-grape/grape/blob/master/lib/grape/dsl/routing.rb#L80

Ah, so it's not a rails command at all.

I think it must just be a way to register the current code with the application as "API::V1::Base". I just can't make any sense of it any other way.

Thanks!

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

Peristalsis posted:

Ah, so it's not a rails command at all.

I think it must just be a way to register the current code with the application as "API::V1::Base". I just can't make any sense of it any other way.

Thanks!

Yeah, Rails will use `API::V1` when handling routes. If the route matches `API::V1` Rails is done an Grape takes over routing.

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".
Out of curiosity what's the advantage of rails with grape vs rails::api ?

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

xenilk posted:

Out of curiosity what's the advantage of rails with grape vs rails::api ?

At this point probably just familiarity with Grape (if you have it). Rails 5 has rails-api merged in so you can rails new <app> --api now and its great.

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".

necrotic posted:

At this point probably just familiarity with Grape (if you have it). Rails 5 has rails-api merged in so you can rails new <app> --api now and its great.

So for someone like myself who hasn't been exposed to grape, rails --api should probably be a better way to go right?

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

xenilk posted:

So for someone like myself who hasn't been exposed to grape, rails --api should probably be a better way to go right?

Yeah, I'd recommend it. Its "just" rails, but with HTML-related things removed (eg no actionview), so there's nothing new to learn.

edit: To be fair, Grape does provide some nice extras (like the parameter contracts), but much of it is doable with rails-api just fine (eg using Strong Params for contracts, documentation using sdoc/yard as usual).

necrotic fucked around with this message at 00:29 on Jun 25, 2016

Pardot
Jul 25, 2001




If you're doing just an api, check out https://github.com/interagent/pliny , it's patterns from the heroku api extracted out to a small framework on top of sinatra.

Hadlock
Nov 9, 2004

I need to run some bash scripts by clicking on a link in my rails app, what's the best way to go about that

rails s is giving me messages about permission denied

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
Simplist way would be to do

code:
system('rake whatever:cool_stuff &')
If you need more structure you could look into setting up a job queue.

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

Hadlock posted:

I need to run some bash scripts by clicking on a link in my rails app, what's the best way to go about that

rails s is giving me messages about permission denied

Make sure the script is chmoded +x!

MasterSlowPoke posted:

code:
system('rake whatever:cool_stuff &')

This works, but beware that if the parent process dies the spawned one will be killed if it hasn't finished. Also you have no way to limit the number of invoked processes without tracking all of that yourself. Someone could spam your button and murder all of your boxen by invoking a shitload of processes.

Background queues are the best way to do process invocation unless you have a really good reason to invoke it inline with the request. They implicitly have a max throughput so the process count only gets out of hand if you configure it that way.

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Hadlock posted:

I need to run some bash scripts by clicking on a link in my rails app, what's the best way to go about that
That depends on what you're trying to accomplish. What are the broad strokes?

Hadlock
Nov 9, 2004

I... I think I'm trying to reinvent Jenkins/Atlassian Bamboo :smithicide:

bash bullshit:

#PULL from github
#BUILD the container
#PACKAGE it for the update server
#PUSH it to cloud storage
#UPDATE the update server

^^ this already works and is tightly modeled after what's already in jenkins and bamboo, just need to call it from ruby on button press :effort:

and then I have a ruby interface for VMWare, rbvmomi/vmonkey, which is going to spin up a new VM from an OVA that is in the cloud (not yet implemented)

finally it's going to kick off testing of some stuff and cram the results in a DB somewhere.

honestly I would just piggyback on top of what he's built/configured, but he's like a bull in a china shop and breaks things without warning constantly so i'm routing around all of it

I would probably look in to gems etc for all this except it's a pretty custom build process and we have a goofy nonstandard code signing process

Right now I'm looking at making a app/views/deck/index.html.erb and in it there's a button that runs all the #bash stuff and returns some message when it's done, a button that runs all the VMWare stuff, returns a message when it's done, and a button that runs all the test stuff, returns a message when it's done, and a link to some updated grafana stuff, and one big button that runs the whole deck from top to bottom and takes you to the results when it's ready.

Then write api endpoints for each button

Huzanko
Aug 4, 2015

by FactsAreUseless
Anyone have any thoughts on TDD?

If you find it's worth doing do you have any learning resources to recommend?

When starting out with TDD isn't it a risk that your code won't pass a test because you aren't properly writing the tests because you don't know how to write tests?

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
I bought the book Rails 4 Test Prescriptions and it was pretty good.

Pardot
Jul 25, 2001




Noam Chomsky posted:

Anyone have any thoughts on TDD?

If you find it's worth doing do you have any learning resources to recommend?

When starting out with TDD isn't it a risk that your code won't pass a test because you aren't properly writing the tests because you don't know how to write tests?

For the first few years after I learned t/bdd I did it pretty religiously. Now that I know when it will be useful and when it's more useful to add tests after (or not at all :ssh:) I do that. But that's only been after the better part of a decade. It is absolutely worth learning though. Testable code is much better, even if the tests weren't there, because then there is at least 2 uses of the code.

I do suppose you have a point starting out that it'd be challenging to know how to write the actual tests. Is there anyone around who does know you can pair with?

Pollyanna
Mar 5, 2005

Milk's on them.


TDD and BDD are good when you know what you want to accomplish, but have no idea how. They're not as great when you know what you want to do, but aren't sure what you're trying to accomplish - which is usually the case when you're first developing a product/MVP or just doing exploratory programming. Everything has its place, and TDD/BDD are no exceptions.

You have to separate the "testing" from the "design" part of TDD and BDD. They're two separate things that inform each other extremely well, but aren't mutually inclusive. Testing, meaning enforcing expected behavior and drawing out a scaffold for your intended design, is always important and greatly improves stability of a project. Design is important as well, but doesn't have as much long-term staying power as testing does, and doesn't contribute directly to managing cognitive overhead and technical debt.

Test only the most important behavior you're looking for. Don't literally test everything about the target, TDD helps you with that by not getting you to specify more than you need and that's a big advantage of starting with tests. Sometimes tests just don't have that much value to write, especially if it's something basic like construction or testing that ActiveRecord saves a thing or whatever.

A good think to keep in mind with TDD and BDD is to write the code you wish you had first, assuming you know what you want to accomplish. That does also mean understanding how to put together a good API - not a REST API, but an API independent of web technology. You know, the old style of APIs. That isn't taught nearly as much, especially because these days when you say "API" people hear "REST endpoints on a server".

All the information I can find on making good APIs is about making good web REST APIs, and not APIs for any other situation. Which is sad, because I can't make a good program at all if it isn't a web project and that sucks :(

100 degrees Calcium
Jan 23, 2011



So I'm just now getting into Ruby On Rails to work on a pet project with a friend. I normally work on .NET web applications that rely on WCF services. I've seen a lot of love for SPAs that use services, and I've seen a bit of love for using Rails 5 API for the service platform for that approach. Is there anything in particular about Rails 5 that makes it a better option for this approach than Rails 4?

Huzanko
Aug 4, 2015

by FactsAreUseless

GlitchThief posted:

So I'm just now getting into Ruby On Rails to work on a pet project with a friend. I normally work on .NET web applications that rely on WCF services. I've seen a lot of love for SPAs that use services, and I've seen a bit of love for using Rails 5 API for the service platform for that approach. Is there anything in particular about Rails 5 that makes it a better option for this approach than Rails 4?

Mostly just that the rails-api gem was baked into Rails 5.

Adbot
ADBOT LOVES YOU

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

GlitchThief posted:

So I'm just now getting into Ruby On Rails to work on a pet project with a friend. I normally work on .NET web applications that rely on WCF services. I've seen a lot of love for SPAs that use services, and I've seen a bit of love for using Rails 5 API for the service platform for that approach. Is there anything in particular about Rails 5 that makes it a better option for this approach than Rails 4?

They've finally have first-class foreign key support in ActiveRecord migrations! I think the rails5 release is focused mostly on performance improvements and bug fixes over new features, with ActionCable being the big exception.

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