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
kalleth
Jan 28, 2006

C'mon, just give it a shot
Fun Shoe
Use simple-navigation for nav - https://github.com/andi/simple-navigation - and cancan for authorization :)

Adbot
ADBOT LOVES YOU

8ender
Sep 24, 2003

clown is watching you sleep
We use simple-navigation on three of our apps and its versatile as hell.

kalleth
Jan 28, 2006

C'mon, just give it a shot
Fun Shoe

8ender posted:

We use simple-navigation on three of our apps and its versatile as hell.

I go out for beer with the current maintainer of simple-navigation now and again :P (mjtko, not andi)

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
What libraries do you use for stemming? I've looked at Snowball-stemmer, but it tends to be unusable for general use, as it overstems the pretty much everything. For example,

football -> footbal
specifically -> specif
verifications -> verif

...and those are just three words off the top of my head.

I looked also at KStem, which seems to be less agressive, but it looks like nobody has ported it to Ruby yet. I'll probably do it myself tomorrow, if anyone doesn't have any better ideas.

Pardot
Jul 25, 2001




Baxta posted:

Pushing a db is coming back with a timestamp error (postgres). Research has dictated that its because im using 1.9.3 and cedar stack only lets you push dbs from 1.9.2 for some unknown bullshit reason.

Any ideas?

Use PGBackups instead of db:push/puill. https://devcenter.heroku.com/articles/pgbackups#importing_from_a_backup Taps needs to die. It's a fantastic geewiz demo, but it has a lot of problems :smith:

Also if you use the new heroku-postgresql:dev plan, you can just psql straight in and/or use pg_restore from your machine.

Once everyone is on that, could probably switch push/pull to just use pg_restore under the covers.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Any suggestions as far as load testing tools go? We had an issue the other day, our daily emails went out in the middle of the day instead of the middle of the night, and we got a huge traffic spike (from links in the emails). One of our apps has a dynamically generated menu, and the 'recipe of the day' and another similar link were being dynamically created instead of being cached. Combine 10,000 users trying to hit the site in a 20 minute period and a slow query to build the link and the site was basically unusable for a while.

I'm going to start by giving this a read:

http://guides.rubyonrails.org/performance_testing.html

I was going to write a script that I can give a list of users/passwords to and have it login then click a few links, and run x amount of those per minute.

I figure there's probably 10 tools out there that can do this already but it might be fun to write one.

We've fixed that issue (and have a list of others from NewRelic data) but I'm pulling for hitting a production app with some traffic BEFORE we let customers go at it. It seems like the last 3-4 new applications we put on the server have had issues like this at launch.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

code:
require "rubygems"
require "nokogiri"
require "openssl"
require 'open-uri'
 
 # ignore SSL errors from staging server
 OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
 doc = Nokogiri::HTML(open("https://staging.myapp.com/login/"))
 
# get the authentication token
 puts doc.xpath("//meta[@name='csrf-token']/@content")
 
Alright, so this can get the auth_token, and I can supply the username and password from a file . But what do I need to use to PUT the login request to the server so I can log in?

After that I'll choose some links to randomly 'click' on, and that's all I really need to do (times a thousand)

IsotopeOrange
Jan 28, 2003

Bob Morales posted:

Any suggestions as far as load testing tools go? We had an issue the other day, our daily emails went out in the middle of the day instead of the middle of the night, and we got a huge traffic spike (from links in the emails). One of our apps has a dynamically generated menu, and the 'recipe of the day' and another similar link were being dynamically created instead of being cached. Combine 10,000 users trying to hit the site in a 20 minute period and a slow query to build the link and the site was basically unusable for a while.

I'm going to start by giving this a read:

http://guides.rubyonrails.org/performance_testing.html

I was going to write a script that I can give a list of users/passwords to and have it login then click a few links, and run x amount of those per minute.

I figure there's probably 10 tools out there that can do this already but it might be fun to write one.

We've fixed that issue (and have a list of others from NewRelic data) but I'm pulling for hitting a production app with some traffic BEFORE we let customers go at it. It seems like the last 3-4 new applications we put on the server have had issues like this at launch.

You could try combining third party solutions such as NewRelic for the measurement and blitz.io for the dummy users. I don't think you're going to get blitz.io to do logins, but it's good for just brute force testing of your resources.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

It was pretty easy to do with mechanize:
code:
require "rubygems"
require "mechanize"
require "openssl"
require 'open-uri'
require "net/http"

# ignore SSL errors from staging server
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG = nil

agent = Mechanize.new
 
target_url = 'http://test.website.com/login'
auth_email = 'bob@website.com'
auth_password = 'password1'

username_input_field = 'auth[email]'
password_input_field = 'auth[password]'

page = agent.get(target_url)
login_form = page.form_with(:action => '/login')

login_form.field_with(:name => username_input_field).value = auth_email
login_form.field_with(:name => password_input_field).value = auth_password

page = agent.submit(login_form, login_form.buttons.first)

page = agent.page.link_with(:href => '/news').click
page = agent.page.link_with(:href => '/live_talk').click
page = agent.page.link_with(:href => '/home').click
page = agent.page.link_with(:href => '/logout').click
So then I just opened up a couple terminals on a few machines and ran that script 10 times each and watched the traffic. Now I'm just working on adding some features.

* Take a CSV file of user, password, subdomain
* Command-line options for number of total times to run and how many in parallel
* Definition file for the site (our sites are similar but have evolved over the last 2-3 years and have slight changes)

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Have you looked at JMeter?

Miskatonic U.
Aug 13, 2008

Do you read Sutter Cane?
Can anyone suggest a good Ruby book for someone who has a reasonable CS background and recent python experience but next to no ruby experience? I just took a job where I'm going to be doing a fair amount of it, and I like to have physical hard copies of a book or two when I'm trying to pick something up.

e: just Ruby, not RoR. More Watir oriented than webdev oriented.

prom candy
Dec 16, 2005

Only I may dance
Design Patterns for Ruby might be good if you're familiar with GoF stuff and would like to see how it's implemented in Ruby. It goes over syntax at the beginning but at a rate that would probably be appropriate for someone with other languages under their belt already.

Steve French
Sep 8, 2003

When I switched jobs and had to pick up Ruby, I was recommended the pickaxe book; worked very well for me:

http://pragprog.com/book/ruby3/programming-ruby-1-9

Doh004
Apr 22, 2007

Mmmmm Donuts...

Steve French posted:

When I switched jobs and had to pick up Ruby, I was recommended the pickaxe book; worked very well for me:

http://pragprog.com/book/ruby3/programming-ruby-1-9

As a .NET developer, I'm looking to get into some Ruby on Rails. If I get this book, are there any other Rails specific books out there worth it? Or are the online guides sufficient?

prom candy
Dec 16, 2005

Only I may dance
If you do get a book make sure it's really recent. Even stuff that covers 3.0 won't have the asset pipeline which is pretty drat important. Rails is still moving really fast and some of the stuff that's written in the earlier books is flat out wrong now.

Doh004
Apr 22, 2007

Mmmmm Donuts...

prom candy posted:

If you do get a book make sure it's really recent. Even stuff that covers 3.0 won't have the asset pipeline which is pretty drat important. Rails is still moving really fast and some of the stuff that's written in the earlier books is flat out wrong now.

Yeah that's what I figured. I'll stick to stuff online and lots of googling... and you guys as well ;)

prom candy
Dec 16, 2005

Only I may dance
I don't know if I mentioned this before but I'm in the Rails mentor program and I'm always happy to help new/intermediate Rails developers work through their issues (although more often than not I'm going to send you to the docs). Feel free to hit me up.

Civil Twilight
Apr 2, 2011

prom candy posted:

If you do get a book make sure it's really recent. Even stuff that covers 3.0 won't have the asset pipeline which is pretty drat important. Rails is still moving really fast and some of the stuff that's written in the earlier books is flat out wrong now.

The PragProg rails book is current for Rails 3.2, at least in ebook form. (Disclaimer: not a rails expert, for all I know the book has taught me many bad things.)

I'd also whole-heartedly endorse the pickaxe book for general Ruby education.

Steve French
Sep 8, 2003

Doh004 posted:

As a .NET developer, I'm looking to get into some Ruby on Rails. If I get this book, are there any other Rails specific books out there worth it? Or are the online guides sufficient?

I wouldn't know, I only know Ruby, no Rails.

Doh004
Apr 22, 2007

Mmmmm Donuts...
Thanks for the tips guys. Amazon has the pickaxe book coming in on Saturday.

kertap
Mar 13, 2010
I was watching Yehuda Katz's railsconf talk and he mentioned in passing that he has to sell consulting clients on why using rails is a good idea but he didn't go into details.

What would be some good reasons you could provide to clients?

prom candy
Dec 16, 2005

Only I may dance
Rapid development, large number of open source libraries, fairly large developer base, built-in security against common attacks.

Oh My Science
Dec 29, 2008
I'm afraid I don't really know how to ask for this properly, but here it goes.

I would like to provide users with the ability to use different view layouts based on their user settings, what would be the best way to accomplish this? ( similar to what Facebook & twitter has done recently )

So far my google-fu has not produced many results, and after reading the API on layouts and templates I feel I may be missing something fundamental.

tima
Mar 1, 2001

No longer a newbie

Oh My Science posted:

I'm afraid I don't really know how to ask for this properly, but here it goes.

I would like to provide users with the ability to use different view layouts based on their user settings, what would be the best way to accomplish this? ( similar to what Facebook & twitter has done recently )

So far my google-fu has not produced many results, and after reading the API on layouts and templates I feel I may be missing something fundamental.

Edit: from the layouts and rendering guide

code:
class ProductsController < ApplicationController
  layout :products_layout
 
  def show
    @product = Product.find(params[:id])
  end
 
  private
    def products_layout
      @current_user.special? ? "special" : "products"
    end
 
end
Where it will use the layout file in your "app/views/layouts/" folder.

tima fucked around with this message at 06:12 on May 20, 2012

prom candy
Dec 16, 2005

Only I may dance
If you want to use a specific view file rather than a layout you can mess around with render :template in your action.

The themes_for_rails gem might be interesting to you as well.

Oh My Science
Dec 29, 2008

prom candy posted:

The themes_for_rails gem might be interesting to you as well.

This is exactly what I wanted, thank you!

prom candy
Dec 16, 2005

Only I may dance
Yeah I just implemented it in a project I'm working on and I was really impressed with it. It's a bit of a pain to get working with the asset pipeline but once you get the folder structure right you're golden.

Oh My Science
Dec 29, 2008
Care to elaborate on that point? I haven't read the documentation yet, but if you can provide advice based on your hiccups it may save me some time.

What was the proper folder structure?

plasticbugs
Dec 13, 2006

Special Batman and Robin
I've decided to push my rails app to github to start building my 'portfolio'. I created a yaml file with all my configuration settings (passwords, email addresses, secret keys, etc) and added it to my .gitignore so that it wouldn't get pushed to github - revealing my passwords, etc.

My question: Now that git is ignoring my configuration settings, how do I successfully push app updates to Heroku without removing 'config.yml' from my .gitignore file?

Removing my configuration file from .gitignore, telling git to start tracking my config.yml again, THEN pushing to Heroku? Seems like that would be WAY too complicated. There must be an easier way, right? What am I missing?

tima
Mar 1, 2001

No longer a newbie

plasticbugs posted:

I've decided to push my rails app to github to start building my 'portfolio'. I created a yaml file with all my configuration settings (passwords, email addresses, secret keys, etc) and added it to my .gitignore so that it wouldn't get pushed to github - revealing my passwords, etc.

My question: Now that git is ignoring my configuration settings, how do I successfully push app updates to Heroku without removing 'config.yml' from my .gitignore file?

Removing my configuration file from .gitignore, telling git to start tracking my config.yml again, THEN pushing to Heroku? Seems like that would be WAY too complicated. There must be an easier way, right? What am I missing?

For heroku you usually use environment variables instead of yml files, check out documentation for "heroku config" on how to add them to your heroku environment.

prom candy
Dec 16, 2005

Only I may dance

Oh My Science posted:

Care to elaborate on that point? I haven't read the documentation yet, but if you can provide advice based on your hiccups it may save me some time.

What was the proper folder structure?

I think it was something like

code:
app
  assets
    themes
      theme1
        images
        stylesheets
        javascripts
  views
    themes
      theme1
It's all noted in the docs somewhere.

Doh004
Apr 22, 2007

Mmmmm Donuts...
I'm slowly going through Rails Tutorial Book and am enjoying it so far. The guide, and everyone else, recommends Heroku which sounds pretty awesome.

My issue is that I have my own dedicated webserver that I used to run a bunch of my other stuff. It's running apache and a whole slew of other stuff that I just throw on there whenever I feel like it. Since I'd like to utilize what I have available, what sort of configuration do you think I should use to set up my production environment so I can deploy to there instead of Heroku?

Doh004 fucked around with this message at 17:35 on May 21, 2012

manero
Jan 30, 2006

Doh004 posted:

My issue is that I have my own dedicated webserver that I used to run a bunch of my other stuff. It's running apache and a whole slew of other stuff that I just throw on there whenever I feel like it. Since I'd like to utilize what I have available, what sort of configuration do you think I should use to set up my production environment so I can deploy to there instead of Heroku?

Definitely check out Passenger: http://modrails.com/

clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe
If anyone is in the Madison area or is interested in going to Madison Ruby Conf I will be there speaking and I have a $50 off coupon code for admission: lindseybieda. I will also be speaking at Steel City Ruby Conf which luckily is only $50, so no coupon necessary. :)

Pardot
Jul 25, 2001




tima posted:

For heroku you usually use environment variables instead of yml files, check out documentation for "heroku config" on how to add them to your heroku environment.

This. Use Foreman locally and a .env file, read https://devcenter.heroku.com/articles/config-vars and http://www.12factor.net/config

Doh004
Apr 22, 2007

Mmmmm Donuts...

manero posted:

Definitely check out Passenger: http://modrails.com/

This just got me really excited. :woop: Thank you!

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

clockwork automaton posted:

If anyone is in the Madison area or is interested in going to Madison Ruby Conf I will be there speaking and I have a $50 off coupon code for admission: lindseybieda. I will also be speaking at Steel City Ruby Conf which luckily is only $50, so no coupon necessary. :)

Awesome, I'll be at SCRC with my coworker. I'd say it's a small world but there really are way too many SA members everywhere.

Oh My Science
Dec 29, 2008

Anyone know how to manually install compass in a rails app?

I want to mess around with Susy 1.0.rc.0 but it requires the alpha compass release v0.13.alpha.0. unfortunately they stripped regular compass of its rails integration starting in v0.12, and instead rely on compass-rails, which has not updated to the alpha release.

Any ideas? I keep getting this error:

File to import not found or unreadable: susy


Never mind, found a release candidate of compass rails.

Oh My Science fucked around with this message at 04:19 on May 22, 2012

plasticbugs
Dec 13, 2006

Special Batman and Robin

Thanks tima and Pardot. I'm looking into Foreman and .env now.

EDIT: I successfully got Foreman running locally. I added all my config vars (which were spread across two separate yml files!) to one .env file in my root and added that to my .gitignore. Deleted all my config.yml files, committed, & pushed to Github painlessly. That's much better! Thanks guys!

My Foreman Procfile is pretty empty

web: rails s
test: rspec


I'm not too keen on the lack of color formatting in my terminal output after running rspec. Though I understand that can be fixed if I also install and configure Guard for autotests.

For now, is there any way I can run rspec in pretty colors without Foreman, but still load in my testing environment variables from .env? I'm guessing no.

What other things can I do with Foreman that might be useful?

plasticbugs fucked around with this message at 08:00 on May 31, 2012

Adbot
ADBOT LOVES YOU

Strong Sauce
Jul 2, 2003

You know I am not really your father.





So I have 2 model types, Leagues and Players. Leagues can have Players, and Players can be in different Leagues.

You can add players and leagues separately, but I'm trying to assign an already created player to the current league. Before I would just do League.find(params[:league_id]).players.create(params[:player]) to add players to a league, but that method doesn't help me much for existing players.

Essentially what I want to do is just add into the join table that player with :player_id is now also in league :league_id. But I don't want a new entry in the player table.

I haven't done Rails in a while so I'm blanking out here. Any help?

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