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
Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Nolgthorn posted:

I've been toying around in Rails 4 using the screencast from Ryan Bates (that stuff is good).

Rails 4 is using minitest, which is awesome. But by default when you create a new model tests in Rails are being wrapped in TestCase which I guess is designed to make minitest look and act like test unit. Is there any way to tell Rails "no I want minitest I don't need your ridiculous extra pointless layers of complexity". Or do I just hack at the tests to make them use minitest and minitest::spec myself?

Answering my own question from a few pages ago in case it is helpful to someone else. Default support for Spec was one of the many things taken out of Rails 4 in order to expedite initial release so to get it working use this unofficial gem.

https://github.com/metaskills/minitest-spec-rails

Adbot
ADBOT LOVES YOU

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.
I've been using Sublime Text 2 for rails for a few weeks, and generally love it. However, after rebooting my machine today, its ruby linter is acting up. It is complaining about things like this:

Ruby code:
def challenges_query(params={})
  p = { id:         11,
        start_date: 7.days.ago.strftime('%F'),
        end_date:   Time.now.strftime('%F') }.merge(params)
  result = do_stuff_with_p(p)
  result    
The linter highlights the definition of p, and says "Odd number list for Hash; Syntax error, unexpected ':'".

Any idea what the hell is going on?

Civil Twilight
Apr 2, 2011

The linter is checking your code with ruby 1.8 (probably the default system ruby), which doesn't have that hash syntax. Make sure you're getting the right version of ruby at the command line, and you might need to configure SublimeLinter to use a specific ruby instead of the default.

Lexicon
Jul 29, 2003

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

Civil Twilight posted:

The linter is checking your code with ruby 1.8 (probably the default system ruby), which doesn't have that hash syntax. Make sure you're getting the right version of ruby at the command line, and you might need to configure SublimeLinter to use a specific ruby instead of the default.

Yeah, that makes sense, however:

code:
$ which ruby
/Users/me/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
Also, when I set SublimeLinter's ruby executable explicitly:

code:
{
  "sublimelinter_executable_map":
  {
    "ruby": "/Users/me/.rvm/rubies/ruby-1.9.3-p0/bin/ruby"
  }
}
I get the same problem with the linter. Very weird...

how!!
Nov 19, 2011

by angerbot
When I do gem server and then go to http://localhost:8808 I see rails 3.2.11 listed, but when I type rails in the command line, it says -bash: rails: command not found. What can I do to fix this. I'm new to ruby, but have a lot of python experience. I'm using OSX Lion, and installed ruby via homebrew. I tried uninstalling ruby, then re-installing, but that had no effect.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!
Not sure how homebrew ruby adds executables from gems- have you considered rbenv?

Steve French
Sep 8, 2003

how!! posted:

When I do gem server and then go to http://localhost:8808 I see rails 3.2.11 listed, but when I type rails in the command line, it says -bash: rails: command not found. What can I do to fix this. I'm new to ruby, but have a lot of python experience. I'm using OSX Lion, and installed ruby via homebrew. I tried uninstalling ruby, then re-installing, but that had no effect.

Yes, but how did you install rails? You know rails is not the same thing as ruby, right?

Civil Twilight
Apr 2, 2011

how!! posted:

When I do gem server and then go to http://localhost:8808 I see rails 3.2.11 listed, but when I type rails in the command line, it says -bash: rails: command not found. What can I do to fix this. I'm new to ruby, but have a lot of python experience. I'm using OSX Lion, and installed ruby via homebrew. I tried uninstalling ruby, then re-installing, but that had no effect.

According to the Homebrew wiki your rails executable may be in ~/.gems/bin; make sure that's in your PATH. You might consider putting
code:
gem: -n/usr/local/bin
into your ~/.gemrc and reinstalling.

Or use rvm/rbenv/chruby/whatever.

Coco13
Jun 6, 2004

My advice to you is to start drinking heavily.
I've been going through the book Ruby on Rails Tutorial, and after running into trouble with my .css file not being uploaded, decided to update Ruby and Rails. Well, now when I run 'rails server' I get an error:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in 'require': cannot load such file -- sqlite3 <LoadError>
That's followed by a long trace to 'from script/rails:6: in <main>. It's something that happened by updating, because I can get a new program up and running easily. Any ideas?

Pardot
Jul 25, 2001




Coco13 posted:

I've been going through the book Ruby on Rails Tutorial, and after running into trouble with my .css file not being uploaded, decided to update Ruby and Rails. Well, now when I run 'rails server' I get an error:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in 'require': cannot load such file -- sqlite3 <LoadError>
That's followed by a long trace to 'from script/rails:6: in <main>. It's something that happened by updating, because I can get a new program up and running easily. Any ideas?

Try doing bundle install
It will install all the gems you need for your project. You may have to install bundler again though, that's gem install bundler

Physical
Sep 26, 2007

by T. Finninho
Ruby code:
super do |success, failure|
end
What is this construct called so I can google it and read more about it.

Kallikrates
Jul 7, 2002
Pro Lurker

Physical posted:

Ruby code:
super do |success, failure|
end
What is this construct called so I can google it and read more about it.

Ruby code:
do |var1,var2| 
#code
end
Is a block with two variables, code inside the block gets executed in scope of the two variables. Can also be written in the form {|var1,var2| #code}

Ruby code:
super 'block'
Passes the block to self's super: the class from which self directly inherits from.
So when inside a method instead of self.method('block') its doing super.method("block")

Kallikrates fucked around with this message at 22:10 on Jan 23, 2013

Physical
Sep 26, 2007

by T. Finninho
Thanks but where do I find some official documentation on that stuff. Do both the scopes get executed simultaneously?

I am probably way off, but I don't know what to call this when I check the ruby and rails docs.

Kallikrates
Jul 7, 2002
Pro Lurker
Blocks and inheritance are ruby; not rails. So any references strictly related to ruby would be a good place to look. http://www.ruby-doc.org/docs/ProgrammingRuby/

Physical
Sep 26, 2007

by T. Finninho
How do var1 and var2 get used in the block? For context, this is for a def create/update in a controller using inherited resources.

e: Maybe the code I am looking at was written wrong. I found this example
Ruby code:
    super do |format|
      format.html { redirect_to root_url }
    end
Not sure what the other variable would be used for in the example a couple post ago. I also don't get what format is tied to, is it what super returns? Or does it tack on some extra commands?

ee: It talks about it more here https://github.com/josevalim/inherited_resources Sorry for bugging you guys.

eee: One question still remains, why the .html part? Why can't it just be
Ruby code:
failure { #my extra stuff here }

Physical fucked around with this message at 22:34 on Jan 23, 2013

Kallikrates
Jul 7, 2002
Pro Lurker
That depends on the methods implementation, For example Hash#each accepts a block that is called on each |key,value| pair.
Enumerable#inject accepts a block that is called for each object in an enumerable on an accumulator: |memo, object|

I looked up ActiveRecords::Base create and update and they don't look like what you are talking about. with respect to success and failure

Coco13
Jun 6, 2004

My advice to you is to start drinking heavily.

Pardot posted:

Try doing bundle install
It will install all the gems you need for your project. You may have to install bundler again though, that's gem install bundler

Worked like a champ, thanks!

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
Two somewhat related questions:

So the @ symbol means a var is scoped within a model/object, correct? So this means that using @ in a controller doesn't really do anything?

Second: It seems like the same scoping applies to helpers. How to helpers work exactly and what is the best practice with them? I realize you have to require them by your controllers in order to make use of them -- does that mean it's generally bad practice to use a helper within a controller?

I'm just really confused about what should be in a helper and what should be in a model. I've always read "skinny controllers, fat models," but in the tutorial I went through, the practice seemed to be "skinny controllers, skinny models, fat helpers."

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

chumpchous posted:

Two somewhat related questions:

So the @ symbol means a var is scoped within a model/object, correct? So this means that using @ in a controller doesn't really do anything?

Second: It seems like the same scoping applies to helpers. How to helpers work exactly and what is the best practice with them? I realize you have to require them by your controllers in order to make use of them -- does that mean it's generally bad practice to use a helper within a controller?

I'm just really confused about what should be in a helper and what should be in a model. I've always read "skinny controllers, fat models," but in the tutorial I went through, the practice seemed to be "skinny controllers, skinny models, fat helpers."

The @ sigil scopes a variable to an instance. Models are usually instances, and so are controllers. During a rails request, you only ever deal with one controller anyways.

Helpers are mixed in to controllers. They have access to a controller's instance variables. Views also run in the scope of a controller. They have acces to the controller's instance variables.

Not every tutorial is equally good.

Into The Mild
Mar 4, 2003





edit: ignore this

Into The Mild fucked around with this message at 01:29 on Jan 26, 2013

Pardot
Jul 25, 2001




Hoollyyyy poo poo learning rails from having no programming experience is overwhelming. I'm coaching a RailsGirls event today, and I can't believe how many different things you have to know.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Yeah, which is why somewhat skeptical of the concept. Teaching programming is hard enough already, but when the first thing you show them is a big, complex framework like Rails, it's a lot of things to learn at once.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Pardot posted:

Hoollyyyy poo poo learning rails from having no programming experience is overwhelming. I'm coaching a RailsGirls event today, and I can't believe how many different things you have to know.

I'm currently teaching a 3 month course for people who have never programmed before, and holy poo poo yes. Our second class was just an overview of what MVC is and where all the various bits fit in, and I think half of the classes eyes were bleeding at the end.

quote:

Yeah, which is why somewhat skeptical of the concept. Teaching programming is hard enough already, but when the first thing you show them is a big, complex framework like Rails, it's a lot of things to learn at once.

We've taken the approach of mixing together teaching Ruby and Rails. Every class has like an hour of Ruby stuff, just enough to teach what you're going to learn on the rails side, and then dig into it with Rails examples. For instance, for our models class, we'll spend an hour going over classes, methods, variables, symbols, hashes, and arrays, and then applying them in making a model (which you don't really NEED stuff like blocks, looping, even conditionals for the most basic models.

Then something like controllers would introduce blocks (to explain respond_to), and conditionals (which you pretty much need in an update method).

I find starting 100% with Ruby just gets people frustrated that they're not actually making something useful. Plus if you're just going with pure Ruby, people won't be motivated to experiment with stuff outside of direct exercises you give them.

Another good thing we've found is to "reset" the project once in a while, or have a few projects to work on, where you can start off fairly sloppy but get to nice, TDD, well structured code by the end. Our first "project" was 100% scaffolded, where people literally didn't modify code outside of "rails generate". The second wasn't TDDed, and was really basic in structure. The third is going to be fully tested from the start.

enki42 fucked around with this message at 00:39 on Jan 27, 2013

waffle enthusiast
Nov 16, 2007



Pardot posted:

Hoollyyyy poo poo learning rails from having no programming experience is overwhelming. I'm coaching a RailsGirls event today, and I can't believe how many different things you have to know.

This sounds like teaching Linear Algebra before someone's taken Algebra I and II.

Pardot
Jul 25, 2001




Dangerllama posted:

This sounds like teaching Linear Algebra before someone's taken Algebra I and II.

So the point wasn't really to give people complete understanding in one day, just to spark excitement in building a web app and getting it running.

Lexicon
Jul 29, 2003

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

Dangerllama posted:

This sounds like teaching Linear Algebra before someone's taken Algebra I and II.

No kidding. Pardot - do yourself a favour and put Rails aside until you're comfortable with Ruby and universal programming constructs such as looping, objects, etc. I'm an experienced software engineer and I find Rails to be a big beast to handle at times.

Lexicon
Jul 29, 2003

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

enki42 posted:

I find starting 100% with Ruby just gets people frustrated that they're not actually making something useful. Plus if you're just going with pure Ruby, people won't be motivated to experiment with stuff outside of direct exercises you give them.

Devil's advocate: Why not base a course off something like projecteuler.net (or equivalent - adjust for your audience's interests)? I find that people are surprisingly intrigued to find out that programming opens up a whole world of problem solving that was previously inaccessible.

waffle enthusiast
Nov 16, 2007



Pardot posted:

So the point wasn't really to give people complete understanding in one day, just to spark excitement in building a web app and getting it running.

So maybe Sinatra?

Ninja edit: I understand what you're saying. Learning programming principles doesn't really get the old juices flowing past the age of 20-something. People want to see the fruits of their labors rather than, "Oh hey, look...I just printed out a fibonacci sequence. :smith:" Just sounds like you might have the opposite problem with Rails. Not just folks not getting the framework, but folks not having enough time to soak up the foundations they're going to have to grok in order to move forward afterword.

waffle enthusiast fucked around with this message at 04:24 on Jan 28, 2013

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

Lexicon posted:

No kidding. Pardot - do yourself a favour and put Rails aside until you're comfortable with Ruby and universal programming constructs such as looping, objects, etc. I'm an experienced software engineer and I find Rails to be a big beast to handle at times.

I want to quote this to keep it around. :allears:

Pardot
Jul 25, 2001




Dangerllama posted:

So maybe Sinatra?

Yeah I agree. I told the organizers that that might have been a better starting point for next time. Having everything in one file would have been much easier I think, than having to learn some of the shell + starting/stopping rails + rails generators + migrate + css + gems + html + erb + etc etc. Sinatra wouldn't cut down on that list that much, but even a little would help.

It was really awesome that by the end of the day they could share the app with their friends after pushing it live. I was super impressed at how far they were able to get.

edit:

The Journey Fraternity posted:

I want to quote this to keep it around. :allears:

Heh, to be fair though I can see how you could misinterpret what I posted without context.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
I wonder if some simple visual-ish programming tool would be a better choice. Maybe something like what Resig & Khan Academy are doing.

http://www.khanacademy.org/cs/intro-to-variables/825241936

MrDoDo
Jun 27, 2004

You better remember quick before we haul your sweet ass down to the precinct.
Anyone here gonna be at Heroku's Waza next month?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I learned how to use Ruby and Rails simultaneously. I kind of regret that now and wish I'd learned Ruby first. It's a spectacular language but often when I use it I mix up what is just Ruby and what is Rails.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Lexicon posted:

Devil's advocate: Why not base a course off something like projecteuler.net (or equivalent - adjust for your audience's interests)? I find that people are surprisingly intrigued to find out that programming opens up a whole world of problem solving that was previously inaccessible.

The short answer is that we've tried this, and ultimately it does end up a bit frustrating for people to not be able to "do anything" with the programming knowledge they've learned over the course of a lesson.

I think there's a couple of extremes here - I don't think anyone would argue that you shouldn't dive straight into Rails with absolutely no understanding of Ruby, and also that you don't have to know the language inside and out before you're even allowed to touch Rails. For us, calling out Ruby seperately and introducing concepts a little at a time, and tying them to practical examples has been extremely helpful.

quote:

It was really awesome that by the end of the day they could share the app with their friends after pushing it live. I was super impressed at how far they were able to get.

This is basically the reason that we went with. When we ran pure Ruby workshops, people were excited but a little frustrated that they hadn't really "made" something. When we ran a course that started with something as basic as just scaffolding out a project, people were way more excited, even if they didn't understand everything that was happening.

Sinatra is kind of a weird case - on one hand, it's REALLY easy to get something incredibly basic up. On the other hand, once you start to extend that beyond basic applications, you hit a bit of a wall where you need to understand how a lot of stuff works and how to best structure an application. I kind of disagree with the idea that Sinatra is a good tool to teach new programmers beyond the most basic "Hello World" sites.

Physical
Sep 26, 2007

by T. Finninho
Whenever someone wants me to teach them programming from zero knowledge I follow this list:
1)Entry point (everything's got one, somewhere. Sometimes it's better to just accept it on faith)
2)Loops
3)The main loop ("do forever while user doesn't exit")
4)Cooler versions of loops (for each, .each, etc)

Then after that I get into functions and classes. Variables are handled along the way. But the entry point and loops is the one I think helps the most. Everything started from there.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
The funny thing about teaching Ruby from a rails concept is that a lot of those assumptions don't really apply though.

1. There isn't an "entry point" for a typical Rails application. I mean, obviously there is, but it's not something that you really need to know about off the bat, and thinking of a Rails app in terms of a normal procedural program can be confusing for newbies. The "main loop" is even more obscured and isn't something any Rails user is likely to encounter pretty much ever (seeing as it isn't even really in Rails per se)

2. You can actually go a long way without loops in Rails, but it does demand that you know some other programming concepts before that. Here's what we do:

Models - Learn classes, methods, arrays, hashes, variable scoping
Controllers - Learn conditionals, boolean logic
Views - Learn loops (to deal with the .each that you're going to have in your index view), talk about blocks a bit.

Physical
Sep 26, 2007

by T. Finninho
I can't imagine being a "new person" and not falling asleep through all of that.

MVC would be day two, I at least have to explain to people that somewhere there is an entry loop, otherwise they think "magic" and that doesn't really lead to good programmers.

tima
Mar 1, 2001

No longer a newbie
What I like to do teaching ruby is make a little game in a couple of hours that lets users work with main loop, input, output and some simple logic. I actually used both classes and testing in my game, but you can just do methods to keep it simple. Last time i did the hangman game and it was fairly fun to implement and play with afterwards.

Then next lesson you can convert it to rails version and show that main loop => rails server, input => routes, output => views, controller + model => logic.

Physical
Sep 26, 2007

by T. Finninho

tima posted:

What I like to do teaching ruby is make a little game in a couple of hours that lets users work with main loop, input, output and some simple logic. I actually used both classes and testing in my game, but you can just do methods to keep it simple. Last time i did the hangman game and it was fairly fun to implement and play with afterwards.

Then next lesson you can convert it to rails version and show that main loop => rails server, input => routes, output => views, controller + model => logic.
This is pretty much what I do. The fun part about programming is making games. Even in high school I saw algebra as it applied to making vidya games, which helped me get more out of it than my other classmates.

Adbot
ADBOT LOVES YOU

kitten smoothie
Dec 29, 2001

Using Devise? Patch it. Sounds like this is another drop what you're doing and get on it sort of patch.

http://blog.plataformatec.com.br/2013/01/security-announcement-devise-v2-2-3-v2-1-3-v2-0-5-and-v1-5-3-released/

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