PDA

View Full Version : Ruby on Rails



Euler
10-08-2015, 10:57 AM
So,
using lich got me interested in ruby. I wrote a cool little thing in ruby and want to share it with some folks.

I have no formal education in programming, so I get a little lost with jargon sometimes. This is what I would like to do:

I bought a domain. I would like to run my ruby code so that people can go to the website and mess with it.

I think I need to learn rails for this.

I need resources to learn rails. I am doing codeacademy and "rails for zombies"

EXTERNALITIES:
I DO TONS OF PROJECTS.
I have done things from buying a spinning wheel to make yarn from cat hair, to developing an indoor aquaponics set up that supplies all my family's veggies year round. My projects often fail and become expensive and sometimes disgusting piles of junk sitting in a corner. (The time I tried to rig up a system for recycling cat litter and my urine by making black powder from it) As a result, I have a very short leash when it comes to spending money on my projects. So, all this to say that closer to "free" is better.

Anyone see holes in this plan or have suggestions for next steps?

**In before "I see holes in your mom," or variations of the same.**

Euler
10-10-2015, 09:54 PM
I am trying to write a thing that will make flash cards for my kid. The idea is that it starts at a low level and will make hard cards as he gets them right. Anyway, I wrote a block called card_generator.

It is supposed to build a set of 121 cards and store them as a hash. I am using the key as the card number for another part of the program. The value of the hash is an array [the_first_number, the_second_number, the_level, the_box]

The array is used in other parts of the code later on. So anyway, this thing works in the block, but it doesn't return the hash. I get an object error in the main body.

can one of you give me a tip?

***in before "I got a throbbing tip for your anus" or variations of same.***

here is my code:

def card_generator(level)
cards=Hash.new
id=(level - 1 )*120 + level
num1 = (level -1)*10
num2 = (level -1)*10
121.times{cards[id]=[num1, num2, level, 0]
if num1==(level *10)
num1=(level -1)*10-1
num2+=1
end
id+=1
num1+=1
}
cards.each{|x,y| puts "#{x}=> #{y}}"} #<-puts out the exact hash I want! yeah! : )
return cards
end


puts "what level you want"
level=gets.chomp
level = level.to_i
card_generator(level)

cards.each{|x,y| puts "#{x}=> #{y}}"} # <- gives me card_generator.rb:28:in `<main>': undefined local variable or method

m444w
10-10-2015, 10:10 PM
If you're going to post large chunks of code and ask people to review them, you should at least put them in a gist, if not a git repo, otherwise it's a real pain to read without proper whitespace and syntax highlighting.

https://gist.github.com/

Also:

http://railscasts.com/

Euler
10-10-2015, 10:30 PM
If you're going to post large chunks of code and ask people to review them, you should at least put them in a gist, if not a git repo, otherwise it's a real pain to read without proper whitespace and syntax highlighting.

https://gist.github.com/

Also:

http://railscasts.com/

I don't know what that means. I don't know what any of this means.


https://www.youtube.com/watch?v=lJ0yD-9CDwI

Euler
10-10-2015, 11:04 PM
https://gist.github.com/MathBeast/f4fa007ead91c6ac98e0#file-gistfile1-txt


Is this right?

Tgo01
10-10-2015, 11:47 PM
I'm not exactly sure if this is the problem but from a quick glance....

cards.each{|x,y| puts "#{x}=> #{y}}"}

Looks like you have an extra } bracket there.

Euler
10-11-2015, 12:05 AM
yes. yes I did. This did not fix it though, sadly.:compbash:

Euler
10-11-2015, 12:09 AM
fixed it. The cards hash needed to be a @cards hash.

:blush: