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

Adbot
ADBOT LOVES YOU

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

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Does anyone have experience with subdomains in rails?

Basically I have a couple of routes that use the subdomain: /.+/ constraint on the site, the subdomains are only used for a small part of the site.

So when the user visits foo.mysite.com the problem is that all the links (e.g. navbar and footer) now link to urls with the subdomain, for instance instead of mysite.com/contact it will be foo.mysite.com/contact.

I know I can change the links from relative to absolute path (e.g. my_path_url(subdomain: false) ), but doing that for all the links in my application seems like a bad idea. Is there some way to configure rails to not link to subdomains unless it is explicitly stated or perhaps some other solution?

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Maybe I'm not getting something but I don't understand how this will help me with linking.

Currently my navbar has something like -- link_to contacts_path, and I always want it to link to mysite.com/contacts. However if the user is on foo.mysite.com that link will go to foo.mysite.com/contacts.

I don't need subdomains for most of the site (just on one controller), the parts where I need them record lookup is already done via subdomains.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

necrotic posted:

I see two options:

  • Add a main_link_to helper (or some such name) that always passes subdomain: false as an option
  • Setup a new link_to using alias_method_chain and default the subdomain option to false (but still allow it to be specified at call time)

The first option is more explicit, but requires you to use a new method for nearly all of your links. The second would be more "transparent", but could catch a new developer by surprise.
In the end I went with just changing footer and navbar links to absolute urls, cause I realized that's the only place I would have to make that change so it wasn't that big of a deal.

But in any case I appreciate the help.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

xenilk posted:

I have a question for folks who work professionally in a Ruby environment. What type of testing do you use? Reading a lot it seems like Test::Unit, Minitest and RSpec are the most popular but I can't really decide which way I should go that I would benefit the most in the field.
RSpec + Capybara

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

kayakyakr posted:

I hate testing (as I've attested to many times in this thread), but I've settled on RSpec + capybara as the testing that I hate the least.
May I ask why? Personally coming from a project that was pretty big and had no tests to a smaller one but with good test coverage is a night and day difference. Yes they can be boring to write, but they certainly save a lot of time in the end.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Does anyone have experience with Heroku and diferrent locale settings for different parts of site?

My code basically looks like this, and it works locally but on Heroku it just stays on the default locale.
code:
def set_locale
    if some_condition
      I18n.locale = :en
    else
      I18n.locale = params[:locale] || I18n.default_locale
    end
end

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

quote:

# Use a set for O(1) include?
That's nice, never realized this.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
I got 99 problems and RVM is one.

So I open up the terminal (on Ubuntu 14.04) and:

code:
>> which ruby
/home/me/.rvm/rubies/ruby-2.2.2/bin/ruby

>> cd myapp
>> rails s
The program 'rails' can be found in the following packages:
 * ruby-railties-3.2
 * ruby-railties-4.0

>> rvm use 2.2.2
Using /home/me/.rvm/gems/ruby-2.2.2  # different folder, still in .rvm though???
>> which ruby
/home/me/.rvm/rubies/ruby-2.2.2/bin/ruby  # still the old folder

>> rails s
# server and everything working normal
:psyduck:

This is happening after I pull an update of the app from the repo and ran:

rvm install 2.2.2
rvm use 2.2.2 - default
bundle install.

Now I have to run rvm use 2.2.2 every drat if I want to work on the app, before that everything worked fine. I don't have much experience with RVM since I use rbenv on other computers, and basically I have no idea WTF is going on whatsoever.

Gmaz fucked around with this message at 15:08 on May 11, 2015

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Already have the .ruby-version and .ruby-gemset files with proper versions inside and this is the relevant line in my .bash_profile:

code:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Guess I'll try running the rvm get stable command.

EDIT: Ran the command, nothing changed.

Gmaz fucked around with this message at 15:29 on May 11, 2015

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Yeah I have all those things. I just ran bundle install again when it was complaining and now everything works. I guess it didn't install the gems for my gemset, but globally (into the rvm@globals folder, not globally on my system) instead the first time. Weird stuff, but it's resolved now.

Appreciate everyone's effort in trying to help me.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
http://en.wikipedia.org/wiki/Type_inference

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Do you have to display all the files at once? You could have some kind of a widget on your page that would show an x amount of files and then the rest would be paginated. You only load the files you need via AJAX, that way you would avoid the massive query. You could also implement some kind of a search for the files, kind of like Select2 jquery plugin works for select fields.

Maybe I misunderstood your use case though.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
If you order the data on the DB level and use offset and limit you still won't have to load all the data. e.g something like:

Model.order('some_column DESC').offset(page_number * display_results_number).limit(display_results_number)

Gmaz fucked around with this message at 17:50 on Jun 3, 2015

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
I've been getting into Elixir lately too, the language creator (Jose Valim) is a core Rails contributor and the author of Devise authentication gem. The whole language runs on the Erlang VM (usually called BEAM), the syntax has some Ruby influences but the language is functional so in reality there is not so much crossover, still it's very interesting to learn especially if you want to build a system that can scale easily.

The performance of the Phoenix web framework (basically Rails of the Elixir world) is awesome, you can see requests being served in microseconds.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

Hadlock posted:

We have our primary RoR app running in one docker container, and a delayed job worker running in a different container. This is a problem as the system was designed for the delayed job worker to build the massive PDF report and drop it on the file system for the primary app to pick up and serve out to the report requester.
Is there a specific reason why you're storing this report on the file system as opposed to some cloud storage?

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
If you have any kind of javascript running, integration tests are still dogshit slow in my experience and they can get unstable. And if there's one thing you can still test in the controller specs (and which controllers are used for anyway), it's the HTTP response so I don't see anything necessarily wrong with you writing them and you shouldn't get any deprecation warnings.

However if you write an integration test that checks the same thing basically (e.g. if you want to know that a specific flash message appeared for a non admin user and ends up redirected), then having a controller test seems redundant.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
If you do JS client + API with Rails do you make them as two completely separate apps or is the client still integrated with Rails/Asset pipeline?

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Enums were introduced in Rails 4.1, so you never really had chance.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
I usually use this gem when dealing with cron jobs:

https://github.com/javan/whenever

Makes it a little bit simpler than pure cron IMO

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

Mathematicus posted:

Edit: I should note that we're looking to use it as a more dynamic and customized scaffold system - something like the built-in scaffold generation, but more extensive, and easy to modify centrally on an ongoing basis. The reviews of it that I'm finding seem to have an "I can take it or leave it" conclusion.
Yeah I think for your purpose Administrate would be the best option.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

xtal posted:

A well-rounded programmer should IMHO know something like C, something like Lisp and something like Haskell. So there are lots of good options and lots of ways to get there. None of the options are untyped dynamic scripting languages. Starting with one of those serves to hamstring your understanding of computer science when it comes time to learn something with the performance, concurrency or type-safety that Ruby is unable to provide.
But also learning C is a bad idea if a person will just give up. IMO it's better to start with these untyped dynamic languages (e.g. Python, Ruby) because you'll actually be able to build something quickly and having that feedback loop means A LOT to a newbie. Then after you actually built some stuff it's good to start learning C, when you'll realize how some of the things actually work under the hood.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

quote:

If untyped dynamic scripting languages are all you're capable capable of learning you would be more effective in other fields.

I never wrote that. Just that for a lot of people they might be easier to start with than something lower level like C, that doesn't mean they won't EVER be able to learn C, Haskell or what have you. But they might give up if they start with C, or even start to hate programming if they start with it. I am speaking from my experience and communication with others, that's why I never mention Haskell/LISP cause they're rarely used to teach beginners.

The statement that starting with dynamic languages will somehow make you unable to learn other concepts not present in those languages, is to me ridiculously absolute and I strongly disagree with it.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

quote:

Is there any solution to the n+1 problem in rails for update/creates?
ActiveRecord import might help, that is if you're using AR.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
You can track the state of the job somewhere in your DB - e.g. you can make a model like SomeJobStatus and set its state column to pending before it's run. Then you pass the ID of an instance of this model to the worker and when the job is finished you set the state to finished, error if it breaks etc.

This way you can make a controller action that will return the status of your job - it would just have the query to find that job and serialize it into JSON. You can then poll this action via ajax.

This is just one solution. I don't know if Delayed Job (been awhile since I've used it) automatically tracks these states and if you can get a job_id easily - if it does, you don't have to do manually track this stuff so it'll make your life simpler. I know with Sidekiq you can get the job_id and track job states easily, but it has Redis as a dependency and that costs money on Heroku.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
In any case if an action takes 20 seconds, you should pretty much move it to a background job. Especially with API calls, if there's something like a network error - you can raise an error inside the worker and it'll retry automatically to how many times you've set it.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

Pollyanna posted:

Yet more rails questions. This time it’s rspec, and our model specs take forever to run. The entire test suite takes 45 minutes when split across 8 CircleCI machines, but running just the model specs has easily taken a few hours on my local machine. The problem is that each individual test doesn’t take too long (3~5s maybe?), but they really add up. It doesn’t look like there’s a single egregiously bad spec, they’re just all a few to a handful of seconds long and there’s a lot of them.

I’m still waiting on it to report to me exactly what the gently caress is going on, but does anyone have any advice for speeding up a whole bunch of mediocre specs all at once, without yet knowing what’s slowing them all down?
Can you mock dependencies for test scenarios instead of creating them in the DB, can you just build the model itself instead of writing it to the DB? If you need to change column values to prepare for a test do you do it without triggering callbacks? Can you pull logic outside of models into a PORO and then test that PORO?

These seem like some obvious things to speed up your model specs, hard to tell more without additional context. Handful of seconds for a model spec sounds like a lot of time TBH.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
How would the language the tests are written in make a difference in speed if the executed code is still in a slow language?

EDIT: Also from my experience if it takes you 5 seconds to run a single model spec, then either your test is not written well or the model should be refactored. Slowness of the language is like the last thing I would think about.

Gmaz fucked around with this message at 00:49 on May 5, 2018

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
What if it's more like 2 + 0.001 vs 2 + .01, not counting the time it would take to rewrite all those tests. Again from my experience people often blame the slowness of the language first when it's usually the last bottleneck - at least when it comes to web applications.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
What drivers do you use to run capybara? Is resolution configured the same on CI and locally?

It is possible that the browser resolution is different on CI and the button is hidden at that resolution. However I would expect the test to fail every time on CI in that case.

Also are you using ajax to load the button?Might be an issue there too.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

Sulla Faex posted:

railstutorial.org - was published in 2010, no mention if it's been updated since then
https://www.railstutorial.org/book

It says in the first sentence below the title that it was updated for Rails 6. Also https://guides.rubyonrails.org/ these are up to date.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
I use stimulus for non SPA purposes with my rails projects and I must say I really enjoy it. It's very simple to use, and anyone familiar with JS can pick it up super quickly. Even someone primarily backend oriented like me.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
There are dozens of us who still use Rails. Dozens!

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
I wonder if it could be a http/https thing. Is your local server http?

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
I used it at my previous job few years ago (we actually backported into our Rails 6 application, because 6.1 was not released yet). It has its wonky parts but IMO still beats STI. I remember rewriting a couple of models from STI to delegated types and it really helped with maintainability.

quote:

You could have the message model delegate the entry-related calls back to the entry, but it seems to me like an anti-pattern to have two classes where each is delegating to the other*.
Yeah this is a bit wonky, but it works without any issues. So if you stomach it, conceptually what it does in the end is to give you a unified interface where you don't have to think about whether you're calling the parent or the delegated types.

quote:

Instead of delegation, I could use a method_missing method on one class telling it to go look at the other class before raising an exception, and that should be pretty equivalent.
I think they would implement it like this on the library level, if they were to do it. To me it's better to use the delegate_to because it's more explicit about which methods are being delegated.

quote:

how to think of the resulting pairs of objects (i.e. do we now approach this as a bunch of entries with some delegated objects attached, or a bunch of messages and comments, each with some entry details attached?)
It really depends on the context, in my case I had like 80% of situations where I didn't even need access to entryable object directly or have the need to call the specific delegate classes. In general if I were to use this again, I'd tend to go with the first approach. If I looked at it from the second approach then I would probably keep the models separated and create custom objects when I need to combine data.

Gmaz fucked around with this message at 16:25 on Mar 3, 2023

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Yeah, in that case I wouldn't use the delegated type at all. Usually this happens when data that's coming from a few models has some common attributes and needs to be presented in a combined way. In that case I'd use View objects, Presenters etc. whatever you want to call the pattern.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Why would you delete it from your resume even if you switch languages? At least for me experience is much broader than just using a programming language/framework, and a lot of concepts in software engineering are very much transferable.

As for Rails itself, it's been proclaimed dead for the last 7-8 years but I still see it kicking and new projects/startups being built with it, along with a couple of giants like Github and Shopify. If you like the framework and feel comfortable working with it, I see no reason to switch.

Adbot
ADBOT LOVES YOU

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

quote:

after getting into typescript i was kinda like "gently caress this i'm sick of all the indirection of rails I don't want to do this anymore"
Funny, that's how I feel about our current React (TS) setup at work and not Rails. Between auto generated types from BE to FE, all the libraries for tables/forms, our own hacks built over the top of those libraries and the interdependence between different libraries it's really complex and counter intuitive to figure out a flow of data. Like something as simple as a table, I have to go to through 5 files to figure where the data is coming from and how it's setup. You want do something that would be trivial in plain old HTML? gently caress you! Type checker is nice, but often times it just gets in the way with indecipherable errors that are usually about simple and inconsequential things.

Comparing that and when I work on the Rails part off the app is night and day in terms of ease work and productivity in general. Now I thought it's just due to me being more experienced with Rails, but internal polls in the company (100+ devs) say pretty much the same. People are in general happy with the BE part, but frustrated with FE. Of course it could be due to our setup and React could be a joy to work with in other circumstances but it sure doesn't feel that way to me. From what I heard of Node projects it's not much better. A bunch glued on libraries, that end up looking like a frankenstein Rails anyway but without the standards to quickly figure out a way around.

Gmaz fucked around with this message at 09:42 on Oct 8, 2023

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