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
Molten Llama
Sep 20, 2006

ufarn posted:

Updating rvm and running sudo rvm upgrade 2.0.0 allowed me to upgrade Ruby, but the bundle command isn't recognized. Think it involves playing with my env vars.

You need to install bundler. It doesn't come with Ruby. See smol's post.

sudo chown -R [yourusername]:admin /usr/local/* to fix your Homebrew install's permissions.
sudo chown -R [yourusername]:staff ~/.rvm to fix your rvm install's permissions. (Assuming it's configured for the defaults.)

And once you've done that, quit using sudo for Homebrew or rvm. It's not required for and should not be used with either of them. Homebrew in fact will refuse to run under sudo unless something royally fucks with its permissions. (Which is what happened, judging by your issues and your brew doctor output.)

Adbot
ADBOT LOVES YOU

ufarn
May 30, 2009
Bundle(r) was already installed, but still wouldn't work, but using those two lines fixed it. Thanks so much.

KoRMaK
Jul 31, 2012



Just deployed to heroku. Things are going ok, but when I created the app locally it was for mysql. Now I am trying to switch to postgreSQL. The heroku documentation says my database.yml file gets overwritten with the right info, but it doesn't seem to be working.

code:
       could not connect to server: Connection refused
       Is the server running on host "127.0.0.1" and accepting
       TCP/IP connections on port 5432?
I'm not sure what it is talking about there, since heroku controls the database. What am I not doing to get this setup right?

Pollyanna
Mar 5, 2005

Milk's on them.


If I'm already kinda familiar with Python, what would the advantages be of learning Ruby? What can it offer me that Python can't?

EAT THE EGGS RICOLA
May 29, 2008

Pollyanna posted:

If I'm already kinda familiar with Python, what would the advantages be of learning Ruby? What can it offer me that Python can't?

There's a gem called HTTParty, I'm not really sure what other kinds of questions you might have but they all seem less important in light of that.

Oh My Science
Dec 29, 2008

KoRMaK posted:

code:
       could not connect to server: Connection refused
       Is the server running on host "127.0.0.1" and accepting
       TCP/IP connections on port 5432?
I'm not sure what it is talking about there, since heroku controls the database. What am I not doing to get this setup right?

https://devcenter.heroku.com/articles/rails-asset-pipeline#troubleshooting

Scroll down to the trouble shooting section. I believe this answers your question.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Pollyanna posted:

If I'm already kinda familiar with Python, what would the advantages be of learning Ruby? What can it offer me that Python can't?

They're similar enough that I wouldn't say there are technical reasons to learn.

There might be social/employment reasons to learn: more than one Rails-using company in town recruits Python developers just because they get going in Ruby with less training than PHP or J-language developers.

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.
I'm having a hell of a time testing a redirection from a named route.

Ruby code:
require 'spec_helper'

describe 'tags routing' do
  describe '/fooblar' do
    it 'redirects to /fooblar' do
      get '/fooblar'
      response.should redirect_to 'http://www.google.com'
    end
  end
end
Results in

code:
tags routing /fooblar redirects to /fooblar
     Failure/Error: get '/fooblar'
     RuntimeError:
       @controller is nil: make sure you set it in your test's setup method.
     # /Use
What am I missing here? Seems like this should be an easy thing to test.

Lexicon fucked around with this message at 18:00 on Sep 18, 2013

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug
What spec file? What does the rest of it look like? I can't tell from that snippet what's going on.

KoRMaK
Jul 31, 2012



Oh My Science posted:

https://devcenter.heroku.com/articles/rails-asset-pipeline#troubleshooting

Scroll down to the trouble shooting section. I believe this answers your question.
Yea that was precisely what I needed! Thank you so much. http://rails.liquid-software.com/

The backgrounds for the other slides in the carousel bootstrap layout don't load. I'm not sure whats up with that.

Lexicon
Jul 29, 2003

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

Cocoa Crispies posted:

What spec file? What does the rest of it look like? I can't tell from that snippet what's going on.

Sorry, that's the whole thing, other than 'require spec_helper' at the top. The route /fooblar is set in the routes file and matched to a particular controller method.

it is
Aug 19, 2011

by Smythe
As far as I can tell this is more of a Rails issue than a jQuery issue. I'm currently working on making babby's first webapp and when I explicitly put <script src="the-path-to-jquery-ui-on-the-internet"></script> I can display a modal, but when I put //= require jquery-ui in my application.js it doesn't let me use the dialog() function, which is from jquery-ui. Am I missing something obvious?

Oh My Science
Dec 29, 2008

it is posted:

Am I missing something obvious?

Are you using the jquery-ui-rails gem? If so it's //require jquery.ui.all

https://github.com/joliss/jquery-ui-rails

it is
Aug 19, 2011

by Smythe
I am not.

I fixed this; what was necessary was some combination of rake assets:precompile, deleting the files from /public/assets, and deleting /public/javascripts.

Thanks!

KoRMaK
Jul 31, 2012



I learned the importance of "require jquery_ujs". I thought it was jquery_uis which would be a redundant include. The it dawned on me "ujs = unobstrusive javascript." It's got what remote forms crave.

I spent an hour trying to figure out why my :remote => true form submit's were refusing to submit as js.

Peristalsis
Apr 5, 2004
Move along.

Peristalsis posted:

Oh, and one more question.

I think this came up with a one-to-many relationship between two models/tables, say owners and products (one owner can own many products).

If I create a new product object, and add it to an owner like this "owner1.products << my_new_product_object", then I can see the product in the products array, the next time I execute "owner1.products". However, if I just manually set "my_new_product_object.owner_id = 1", then Rails doesn't add it to owner1.products, even though, as far as I know, the net effect should be exactly the same.

Any idea what's going on here?


kayakyakr posted:

Did you reload owner1 between creating your new product object? Otherwise, it'll probably just cache the last products lookup. Are you use the product object is saving and are you sure that's the proper id?

In case anyone is interested, I think the issue here was that I hadn't saved the model objects consistently, since I was just monkeying around in rails console. If I have owner1 linked to product1 as above, but haven't saved either of them, then owner1.products returns an array with product1 in it, but product1.owner doesn't return anything. I can't reload product1, presumably because it isn't in the database yet, so I think I just have to (carefully) save things before trying to use this particular voodoo.

Coco13
Jun 6, 2004

My advice to you is to start drinking heavily.
I'm trying to create an app that allows the user to keep a log of their weight changes. I'd like there to be one weight per day, and if the user puts in 2 different numbers on the same day, then it overwrites the original. Right now, my code to create the new weight is
code:
	def create
		@weight = current_user.weight.build(params[:weight])
		if @weight.save
			if Weight.where(user_id: current_user.id, date_of_entry: Date.today).exists?
				# Weight.find(user_id: current_user.id, date_of_entry: Date.today).destroy
			end
			flash[:success] = "Weight saved!"
			redirect_to weights_path
		else
			flash[:failure] = "That wasn't a number."
			render 'pages/home'
		end
	end

When the # is removed, it says 'unknown key: user_id'. First, why does it recognize 'user_id:' in the where statement, but not the find? Second, is there a better way to do this that I'm missing?

\/\/\/ Awesome, it's working now, thanks!

Coco13 fucked around with this message at 02:20 on Sep 20, 2013

Molten Llama
Sep 20, 2006

Coco13 posted:

When the # is removed, it says 'unknown key: user_id'. First, why does it recognize 'user_id:' in the where statement, but not the find? Second, is there a better way to do this that I'm missing?

Find only accepts the primary key (id) as a parameter.

If you want to find by a given field or fields, you want find_by:
code:
  Weight.find_by(user_id: current_user.id, date_of_entry: Date.today).destroy
I don't know about better, but you can simplify this:
code:
if Weight.where(user_id: current_user.id, date_of_entry: Date.today).exists?
  Weight.find_by(user_id: current_user.id, date_of_entry: Date.today).destroy
end
down to one line:
code:
Weight.where(user_id: current_user.id, date_of_entry: Date.today).destroy_all
Alternately, you could find_by and update the existing record instead of destroying the existing record and creating a new one. Six of one, half a dozen of the other.

Enforcing a single weight record per day is also ostensibly more appropriate in the model than the controller, and you could implement a callback there (before_create, maybe?) to do it.

Molten Llama fucked around with this message at 01:51 on Sep 20, 2013

prom candy
Dec 16, 2005

Only I may dance
You could use #find_or_initialize_by

code:
@weight = Weight.find_or_initialize_by(user_id: current_user.id, date_of_entry: Date.today)
@weight.assign_attributes(params[:weight])
@weight.save
That will find an existing record and update it, or create a new one if the existing record doesn't exist. There might be a better interface for updating the attributes, I couldn't remember a common one that would work when you don't know if the record is persisted or not.

This code probably should go into the model, or possibly into a DailyWeightSaver service class if this application isn't tiny.

hmm yes
Dec 2, 2000
College Slice
Not related to your question and you may just not have gotten to it yet, but you're going to want to ensure you are forcing time zones. Date.today will use the system clock, not the Rails time zone, and further you probably want to allow users to define what zone they are in.

Pollyanna
Mar 5, 2005

Milk's on them.


Cocoa Crispies posted:

They're similar enough that I wouldn't say there are technical reasons to learn.

There might be social/employment reasons to learn: more than one Rails-using company in town recruits Python developers just because they get going in Ruby with less training than PHP or J-language developers.

That is actually something I was wondering about. The most common languages I see requested on job websites and such are C#/.NET, Java, and SQL, with RoR showing up depending on what I search for. I'm most familiar with Python, so I had been thinking of learning one of those languages just so I'm more hireable. :shobon: What can I say, I need a job.

Also, I was trying out Ruby on some web-based trial...thingy, and I noticed that strings and the like can be modified like, "Jimmy".reverse. Does that mean that each string in Ruby is an object, with associated methods like "reverse"? Or does it work differently in this language?

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Almost everything in ruby (including things like classes, or even the class Class) is an object that you can modify or call methods on. But note that String#reverse doesn't actually modify the receiver, it just returns a new, reversed string.

Smol fucked around with this message at 23:37 on Sep 21, 2013

Pollyanna
Mar 5, 2005

Milk's on them.


I tried running RailsInstaller, but I get this during installation:

quote:

There has been an error.
Error changing group of /opt/rix to rvm
The application will exit now.

I looked it up online and apparently the solution is literally to reboot your computer? :psyduck:

To be honest, I've always had trouble getting Ruby installed on OSX. RVM and stuff like that always broke for some reason, and I'm sick of trying to figure out what the loving problem is.

Would it be worth it to just wipe OSX clean of anything Ruby except for what it came with? Is there a "best" installation manager to use for RoR?

wolffenstein
Aug 2, 2002
 
Pork Pro
Install Homebrew then use it to install RVM (or better RBENV).

Pollyanna
Mar 5, 2005

Milk's on them.


I managed to get RailsInstaller going, and it includes lotsa poo poo like RVM JRuby RBENV Homebrew etc. I assume if I have all that, then I have pretty much anything I need?

wolffenstein
Aug 2, 2002
 
Pork Pro
I guess, but the current version seems to install Ruby 1.9.3 and Rails 3.2. If you're just starting out, you might as well use Ruby 2 and Rails 4.

Pollyanna
Mar 5, 2005

Milk's on them.


Well, I think I finally managed to get my computer to stick with Ruby 2 and Rails 4. What are some good recommended tutorials for learning stuff in Ruby?

wolffenstein
Aug 2, 2002
 
Pork Pro
Rails Tutorial will teach you how to make a Twitter clone.
Rails for Zombies will teach you how to make a Twitter clone for zombies.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
rails tutorial is good and will teach you a lot of other useful skills (git, if you dont know it already) and probably taught half the people in this thread

EAT THE EGGS RICOLA
May 29, 2008

You're going to need an introductory Ruby course first. Do you have experience programming?

I don't think that it's the best way to learn, but you could give Code Academy's Ruby stuff a shot if you wanted a bit of handholding to get started.

I really liked Rails Tutorial, but it's going to suck to do if you know no Ruby at all.

Fillerbunny
Jul 25, 2002

so confused.
If you're looking at books, The Well Grounded Rubyist really clicked for me.

EAT THE EGGS RICOLA
May 29, 2008

What's the best way to set up a date field with an optional month and day? (i.e. if something was made at some unknown point in time in 1850, it would return just the year)

Cock Democracy
Jan 1, 2003

Now that is the finest piece of chilean sea bass I have ever smelled

EAT THE EGGS RICOLA posted:

What's the best way to set up a date field with an optional month and day? (i.e. if something was made at some unknown point in time in 1850, it would return just the year)
I've never used it but there's this gem. From the looks of it, they don't tackle the whole "how do I store this in the database" issue.

Pardot
Jul 25, 2001




Cock Democracy posted:

I've never used it but there's this gem. From the looks of it, they don't tackle the whole "how do I store this in the database" issue.

The answer to that is the tstzrange data type

SQL code:
$ psql
Time: 0.589 ms
psql (9.3devel, server 9.2.4)
Type "help" for help.

=# create table indeterminate_dates(descr text, date tstzrange);
CREATE TABLE
Time: 1.686 ms
=# insert into indeterminate_dates values
('year 2013', tstzrange('2013-01-01', '2014-01-01')),
('sep 2013', tstzrange('2013-09-01', '2013-10-01')),
('sep 26 2013', tstzrange('2013-09-26', '2013-09-27'))
;
INSERT 0 3
Time: 0.973 ms

=# select * from indeterminate_dates where now() <@ date;
    descr    |                        date
-------------+-----------------------------------------------------
 year 2013   | ["2013-01-01 00:00:00-08","2014-01-01 00:00:00-08")
 sep 2013    | ["2013-09-01 00:00:00-07","2013-10-01 00:00:00-07")
 sep 26 2013 | ["2013-09-26 00:00:00-07","2013-09-27 00:00:00-07")

=# select * from indeterminate_dates where '2013-02-10'::timestamptz <@ date;
   descr   |                        date
-----------+-----------------------------------------------------
 year 2013 | ["2013-01-01 00:00:00-08","2014-01-01 00:00:00-08")

=# select * from indeterminate_dates where '2013-09-10'::timestamptz <@ date;
   descr   |                        date
-----------+-----------------------------------------------------
 year 2013 | ["2013-01-01 00:00:00-08","2014-01-01 00:00:00-08")
 sep 2013  | ["2013-09-01 00:00:00-07","2013-10-01 00:00:00-07")

=# \q
$
See http://www.postgresql.org/docs/9.3/static/rangetypes.html and http://www.postgresql.org/docs/9.3/static/functions-range.html#RANGE-FUNCTIONS-TABLE

Legacyspy
Oct 25, 2008
I have a static "info" page under public/info.html.

Is there a simple way to like, have a link to that page on the bottom of every page in my application? Or do I have to add it manually to every view?

Molten Llama
Sep 20, 2006

Legacyspy posted:

I have a static "info" page under public/info.html.

Is there a simple way to like, have a link to that page on the bottom of every page in my application? Or do I have to add it manually to every view?

Layouts are your friend. If you're using layouts for your views, put the link in the layout(s). If you're not using layouts, use layouts.

Or if it needs to be in a different place on each page (and even multiple layouts won't cut it), you could always plop a method into ApplicationHelper to generate the link.

prom candy
Dec 16, 2005

Only I may dance
But seriously, not using layouts is like not using controllers. Use a layout!

Fillerbunny
Jul 25, 2002

so confused.

Please tell me that's pronounced tee-steez-range.

Pardot
Jul 25, 2001




Fillerbunny posted:

Please tell me that's pronounced tee-steez-range.

Haha. Well it's short for timestamptz, which is short for timestamp with timezone, which is the ONLY DATATYPE YOU SHOULD USE TO STORE TIME. loving rails and defaulting to timestamp without timezone for the created_at and updated_at columns. I should send a patch but :effort:

Adbot
ADBOT LOVES YOU

prom candy
Dec 16, 2005

Only I may dance
How do you set that in a migration?

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