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

Hmm I'm still using RVM, guess I'm a noob. But if anything can simplify the Postgres install, sign me up. Although I heard Heroku was building a better management tool which would be super handy.

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.

Pardot posted:

I will help you set up postgres, post any problems you have. I personally just use homebrew for what it's worth.

The tool you're talking about is this http://inductionapp.com/ which while cool, does not help in installing postgres. I'm thinking of making an mac app that run postgres for you, but :effort: and time.

Oh, I have no problem setting it up now that I've done it a thousand times :). But it's a consistent roadblock when I'm trying to ramp up new users to Rails development, as they usually can't figure it out themselves.

Thanks for the helpful offer though. And I'll definitely check out Induction.

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.

You realize there's a giant PaaS that uses Postgres exclusively, right? Not to jump down your throat but are you even reading the thread?

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.

I use Heroku exclusively for my projects because finding good ops people is hard and gently caress if I'm ever touching a server. I break IIS enough to know I'm not the guy for that :). Also I must be the only person in Knoxville who knows what a Rails is.

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.

Well, you'll just get better at Ruby by writing lots of Ruby code. You'll probably have to go back and refactor your first app a poo poo-ton. Just stop writing so much code in the views! This isn't PHP for god's sake. ;)

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.

I'm gearing up for some upcoming Rails job interviews, anyone have study tips?

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.

Be sure to check out Railstutorial.org as it has a ton of great resources.

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.

Tomed2000 posted:

I'm not sure where to begin with this one but I have a Rails app on Heroku right now that uses Devise for handling user authentication and I've got about 50 customers with accounts. I recently wrote a C# application and I'd like to implement some sort of authentication before users can start running this app. Is there any way I can make the Rails app communicate with the C# app? I know this is possible with Microsoft SQL Server and IIS but I'd really just love to send a request to the postgres database on Heroku for validation or use some other technique that allows me to query the Rails app for user login info.

Well, you can take advantage of Rails' RESTful api design. Submit a POST to the corresponding sessions controller (that handles logins) and specify in the headers that you want a json formatted response of some kind. XML would work too I suppose. Then parse the results when they come back from the server in your C# code.
It's really late and I've been coding all day so I might have missed something but that seems like the most straightforward way to do it.

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.

Jam2 posted:

What an acceptable amount of time for it to take to render a view in response to a request? Is 70ms too long in a development environment? As I haven't pushed anything to production, I cannot tell how careful I should be about performance and optimization in the initial development stage. (writing my first major application)

Don't get into premature optimization. Once you deploy on production mode it'll be much faster anyway (because Rails won't have to knock down and reload your classes with every request).

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.

Jam2 posted:

What's the best way to make this readable and within 80 chars per line?

code:
      Listing.within(@region)
             .includes(:region)
             .where('category_id = ?', params[:category_id])
             .text_search(params[:query])
I dunno, just personal preference really

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.

prom candy posted:

Note that in 1.8 you would have to put the dots at the end of the lines rather than the beginning.

Can you do it like this? This is how I like to do it in Javascript but I don't know if it's valid Ruby.
code:
Listing
  .within(@region)
  .includes(:region)
  .where('category_id = ?', params[:category_id])
  .text_search(params[:query])

Pretty sure it's valid.

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.

Jam2 posted:

code:
def self.viewable_by(user)
  user ? self : where("secured = ?", false)
end
what does this do?

returns self unless user evaluates falsy, otherwise returns all records of self's class that have a secured value of false in the database

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.

prom candy posted:

It's checking it against nil, it's basically a really quick way to check if someone is logged in.

Just a thought, couldn't you skip this step by integrating CanCan or the like?

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.

How do you guys usually deal with gem dependency conflicts? Specifically,

code:
Bundler could not find compatible versions for gem "faraday":
  In Gemfile:
    zendesk_api (>= 0) ruby depends on
      faraday (>= 0.8.0) ruby

    fbgraph (<= 1.8.0) ruby depends on
      faraday (0.7.6)

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.

Yeah, that's sorta what I thought... thanks.

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.

epalm posted:

Hi folks! I'm updating Redmine from 1.3.1 to 2.0.3, which involves updating rails 2 to rails 3, among other things.

My current installation is actually a bitnami redmine stack on windows. It installed fine and has been working great for a year now.

I think my options are

(A) try to update rails and rake and all the other things that redmine 2.0.3 requires, and then work my way through the redmine upgrade guide.

(B) store a mysqldump of the database, uninstall the bitnami redmine 1.3.1 stack, install the bitnami redmine 2.0.3 stack (which will have all the necessary dependencies), restore the database, and run "rake db:migrate RAILS_ENV=production" to update the 1.3.1 database to the 2.0.3 schema.

Which one seems like less of a headache?

They both sound like a PITA, but I'd probably just follow the guide. Are you using Pik? It might not apply in this situation but I found it helpful when I developed on Windows. (https://github.com/vertiginous/pik)

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.

So, what's the best approach to enhancing gem-based ActiveRecord extension classes? Specifically I want to add a few class methods to the audited gem.

Suppose I have a "Searchable" module with some helpful class methods that I've successfully integrated into some other ActiveRecord models using ActiveSupport::Concern. It looks kind of like this:

Ruby code:
# app/models/concerns/searchable.rb
# Include this to give your model a searchable pattern
module Searchable
  extend ActiveSupport::Concern

  module ClassMethods
    def search *args*
      # stuff
    end
  end
end
This plays nicely with my user-defined ActiveRecord models but I'm having some trouble opening up the Audited::Adapters::ActiveRecord::Audit class. My current thought process is something like this:

Ruby code:
# lib/audit_extensions.rb
require 'audited'
module AuditExtensions
  def self.included(base)
    # base.send :include, Searchable ??
  end
end
Audit = Audited.audit_class #=> Audited::Adapters::ActiveRecord::Audit
Audit.send(:include, AuditExtensions)
Which doesn't work of course. I can never get past my controller complaining about NoMethodErrors. :(

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.

That's not so bad. I'm on a team that writes migrations that look like
Ruby code:
class CreateSuperUser < ActiveRecord::Migration
  def self.up
    add_column :users, :is_superadmin, :boolean
    u = User.new
    u.email = #
    u.name = #
    u.is_male = 1
    u.is_subscribed = false
    u.password = # yes they really do this
    u.password_confirmation = #
    u.status = 1
    u.zip_code = '01128'
    u.is_superadmin = true
    u.save
  end

  def self.down
    remove_column :users, :is_superadmin
  end
end
I wish I were joking.

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.

It's what happens when you decide to outsource development to a team of Eastern Europeans who don't speak English (our image gallery is spelled "Galery.rb") or care about things like unit test coverage, standards or best practices, and think it's okay to write 500 character SQL queries on a single LOC.

This is for a fairly prominent "daily deals" type site by the way, and the codebase is responsible for processing upwards of 200k in sales / day.

I was brought on last month because the higher-ups were all "oh poo poo we don't have any developers stateside." I'm basically the SQL monkey / put out fires ops guy right now but I'm pushing for a refactor / unit test project before any new features are added. We'll see. At least the pay is good for my area.

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.

prom candy posted:

Have you tried https://github.com/thedarkone/rails-dev-boost

If that doesn't work you'll probably need to profile your requests somehow to figure out where the slowdowns are happening. Does it happen if you don't use the asset pipeline?

If he's on Rails 2 he doesn't have the asset pipeline, which only came about after Rails 3.1.

That plugin looks interesting. It reminds me of how Scribd handled development mode (they have a huge Rails 2 app). They basically ran a watch script (think SASS compiler) that monitored and reloaded classes only when they were modified, instead of dumping the whole app and reloading every class per request.

It's an interesting problem.

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.

Shame Boner posted:

I think I did a bad thing. This morning, mysteriously my rails server wouldn't start. It was bombing out with the message /Users/ShameBoner/.rvm/gems/ruby-1.9.3-p286@rails_3_2/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- trace_nums (LoadError). I suspect that I properly hosed my gemset by doing a bundle update while rubygems.org's dependency API is down. I'm not sure what gem is responsible for the TraceNums class, but it seems to be missing. Is there any way to un-gently caress this gemset? For the time being, I had to go back to using my 1.9.2 version of Ruby.

That's always fun. I hope this isn't for a big project because it could get a little hairy. If your Gemfile.lock is in version control you can look at a previous version where everything was working, then manually go through your gemfile, setting specific versions of all your gems. From there just update as necessary.

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.


Wow, that seems kind of awkward, I didn't know people still inlined ruby in their javascript code. I hate to recommend js frameworks since it seems like you're already really far along with this method, but I've been really happy using either Angular, Backbone, or Knockout.js (with underscore.js as a utility belt) for my ajax-y goodness.

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.

mmachine posted:

Ha! Well it definitely felt awkward.

I'm not opposed to using a JS framework, though I'm wondering if understanding how this works without the framework in place yet will get me a better handle on how these things talk together.

Well the way I use them is, I basically treat Rails like an API / REST layer with routing and business logic, and then the js on the front just talks to Rails.

I think (Backbone || Angular) + underscore would be a good starting point if you're actually interested in using a js framework.

I've used Knockout extensively but that was with .NET, not sure how well it gels with Rails.

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.

Shame Boner posted:

I'd also give Spine.js a look as an alternative to Backbone. Spine is written in Coffeescript, has no dependencies, and is teeny tiny. After learning Coffeescript, I found that it made me love Javascript more, but also never want to write Javascript again, if you know what I mean. There are some ugly parts of the syntax (mixed array/hash objects, I'm looking at you), but I find it much more readable, concise, and faster to write. Unlike Backbone, Spine doesn't really have a concept of a view, so you must plug your own templating solution into it. I use HAML/Coffeescript through the awesome haml_coffee_assets gem.

I'll have to check Spine out, but the main reason I shy away from Backbone is the inevitable function-pointer-callback soup I get mired in for trying to manually render elements asynchronously. The MVVM pattern in Angular seems to solve this problem nicely.

Also, I'm not entirely convinced Coffeescript is better than plain JS. Prettier? Definitely. I'm probably going to wait out the whole "compiles to javascript" language battle that seems to be happening right now and go with the community consensus.

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.

Active Admin + your favorite SVG based javascript graphics library.

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.

If all you care about is running your own SQL commands, look into using the Sequel gem instead of ActiveRecord. But I recommended ActiveAdmin because I think it has a pretty interface :3

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.

Depending on what you're trying to do you could look into extending existing ActiveModel classes with ActiveSupport::Concern (which usually go in app/concerns), or just creating your own folder app/myclasses/my_class.rb, and including it in whatever file you're using the class in. Alternately, load it in your environment config by adding the path there to make it available to all classes.

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.


Speaking of Sequel, I've been using it a lot for production DB scripting here at the office, and was wondering if there's a faster way to do this:

Ruby code:
DB = Sequel.connect('mysql://....AWS/mydb')

f = File.open("my_data.csv", 'r')

DB.transaction do
  until (a = f.gets).nil?
    a = a.strip.split(/,/)
    DB.run("update my_table set some_val=#{a[1]} where some_id=#{a[0]}")
  end
end
Basically a mass update of a bunch of rows, changing only one field per row to a corresponding value. This is more of a general DB question but in the context of the Sequel gem I guess. I wrapped it in a `transaction` but I feel like it might still be opening and closing connections in my until loop (I know this is slow).

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.

Physical posted:

I created a folder in my app directory called classes with a file classes/input_field.rb defined as
code:
module InputField

end
then I tried including it in a controller but I keep getting
uninitialized constant MyController::InputField

Not sure what I am missing here. Eclipse knows that it exists, so the intellisense is working.

What does your controller look like? Are you using relative pathing or including the path in your root environment?

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.

Physical posted:


I'm not sure how to include it in my root env (I'm assuming it's already taken care of since it's in the app directory).


Nope! Check this out:

config/application.rb posted:

Ruby code:
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W{
      #{config.root}/app/models/extensions 
      #{config.root}/app/models/concerns
      #{config.root}/lib 
      #{config.root}/lib/offers_observers
    }

e: looks like syntax highlighting is "broken" for string interpolation inside of a %w. What does SA use for syntax highlighting? Pygments?

A MIRACLE fucked around with this message at 22:08 on Oct 30, 2012

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.

Physical posted:

Thanks found that shortly before you replied. Now my issue is variables.

But now it keeps acting like things are methods instead of variables.

Yeah... you haven't defined name as an instance/class variable for InputFields. There's a shortcut, attr_accessor :my_variable, which is like a getter/setter in C# for example.

edit:

Shortcut for doing this:
Ruby code:
module InputField
  class InputFields
    @nameee = "nothin"

    def nameee= val
      @nameee= val
    end
  end
end
It's all about exposing variables to the outside world. I still don't know why you're nesting this inside of a module though, unless you're going to add a bunch of different classes to it or something.

A MIRACLE fucked around with this message at 22:22 on Oct 30, 2012

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.

Physical posted:

Holy poo poo I did namee and name. Forgot that I wanted to use namee in the controller. Even if I did spell it right I still have to use the attr_accessor.

Thanks for the help!

As for nesting inside a module, I thought I had to. When I drop the module part I get wrong argument type Class (expected Module)

If it's included in the Rails environment you don't have to for classes I think.

But yeah, to include something means that something is a module, and you want to use it as a mixin, ie have that module now be a part of your class, with all its methods and variables and what-not. Just require '../myfile' or whatever in the future, or have it in the environment already.

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.


Use the def initialize constructor.

Ruby code:
class Jedi
  attr_accessor :name
  def initialize
    name = "Luke"
  end
end

class Sith
  attr_accessor :name
  def initialize
    @name = "Vader"
  end
end

puts Jedi.new.name #=> ""
puts Sith.new.name #=> "Vader"

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.

`@name` becomes an instance variable, `name` will just be local to the `initialize` method, and will be garbage-collected when the method is finished executing.

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.

Don't put it in a migration. That poo poo is a nightmare to maintain, esp when you bring new devs on.

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.

I'm going to try damned hard to make RailsConf in Portland next April.

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.

IDK man I would honestly look into Node.js and websockets and stuff if you want to make a chat room. You could probably still hook it up to ActiveRecord if you want a sql log of the messages.

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.

Smol posted:

Just noticed that the mysql gem returns everything as strings (or nil). Why do I have to deal with this kind of crap. :(

Wish I could use PostgreSQL at our shop

If you have a choice you could try using the Sequel gem that's been posted about in this thread like 20 times. It gives you a little ORM to work with if that's your thing.

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.

Knyteguy posted:

Git isn't fetching the sqlite3 files that are present on my development server but I'm guessing that's just a driver? Still really new to the ROR stuff.

https://github.com/Noppadet/RailsBasicApp/blob/master/.gitignore#L11

You should have different databases for development, testing and production anyway.

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.

Does CPanel even support Rails 3?

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