<al2o3-cr>
i was going to try something then, now i've forgot :/
Rich_Morin_ has quit [Quit: Rich_Morin_]
<al2o3-cr>
>> [1,2,3].map { |n, @a = 5| }
<ruby[bot]>
al2o3-cr: # => /tmp/execpad-9563ef90973b/source-9563ef90973b:2: formal argument cannot be an instance variable ...check link for more (https://eval.in/1077093)
<al2o3-cr>
18>> [1,2,3].map { |n, @a = 5| }
<ruby[bot]>
al2o3-cr: # => /tmp/execpad-f2cea7d2c675/source-f2cea7d2c675:2: syntax error, unexpected '=', expecting '|' ...check link for more (https://eval.in/1077094)
<al2o3-cr>
ah, nvm.
<al2o3-cr>
i'm sure you could pass instance variables to blocks but i could be wrong.
Dbugger has quit [Ping timeout: 252 seconds]
mikecmpbll has quit [Quit: inabit. zz.]
p1c0 has quit [Remote host closed the connection]
Dreamer3_ has joined #ruby
ericboehs has joined #ruby
dviola has quit [Quit: WeeChat 2.3]
<al2o3-cr>
baweaver: check this out
<al2o3-cr>
&>> def add(x,y) x + y end; TracePoint.trace(:call) { |tp| tp.self.method(tp.method_id).parameters.each { |_, p| tp.binding.local_variable_set(p, rand(100)) if tp.method_id == :add } }; add 10, 20
<al2o3-cr>
it's MRI internal strings and arrays are funcky.
<phaul>
I think it's chosen as such that if it makes sense to do a == b for a type in a program, like you would actually do it, then a === a in that type. but can be wrong
<roelof>
earlier I used rubyMonk but that one does not work properly anymore :(
PCiobanita has joined #ruby
<PCiobanita>
hi there. I am new here but I need some help with ruby sinatra. Been stuck here for the past few days. I need to solve this in the next few hours. It shoulnt take to long if somone can and is willing to help let me know. also new to the platform.
<havenwood>
PCiobanita: What issue are you running into?
<havenwood>
?ask
<ruby[bot]>
Don't ask to ask. Just ask your question, and if anybody can help, they will likely try to do so.
segy has quit [Ping timeout: 245 seconds]
<roelof>
tryRuby is easy. I think I will start wit the Odin project
<roelof>
is Atom much better then the VSCode ?
sagax has quit [Ping timeout: 258 seconds]
<PCiobanita>
the issue I have is passing params from textarea into sql query. If i hardcode the messege it works. but when i try to use params form from it says undifined method for asnwer class. although it chould work. becuase if I manually post it into PG it actually prints. If i could share mys creen woulve been easier to explain. What i would like is somoen that can help me over discord for like 10 min. if is not to much of an ask. I am q
Rich_Morin_ has joined #ruby
<PCiobanita>
I am quite new so i dont know how to be specific with my issues
<phaul>
no chance to discord with me, but I would take a look at the code if you shared your code one way or an other. github, gists, bitbucket or whatever you like.
segy has joined #ruby
Rich_Morin_ has quit [Quit: Rich_Morin_]
Rich_Morin_ has joined #ruby
Rich_Morin_ has quit [Client Quit]
Rich_Morin_ has joined #ruby
Rich_Morin_ has quit [Client Quit]
Rich_Morin_ has joined #ruby
Rich_Morin_ has quit [Client Quit]
Rich_Morin_ has joined #ruby
Rich_Morin_ has quit [Client Quit]
Rich_Morin_ has joined #ruby
Rich_Morin_ has quit [Client Quit]
hutch has joined #ruby
<phaul>
usually it's a good idea to come with links to the code to IRC
m4rCsi has quit [Remote host closed the connection]
<PCiobanita>
yeah I shoulve removed that. I know the issue with that. is outside the loop
uplime has joined #ruby
hanmac has quit [Ping timeout: 258 seconds]
<phaul>
second issue: the server is getting GET requests on submit not POST.
<phaul>
therefore the post handler in sinatra doesn't run
<phaul>
you should see this on your side if you look at the server log. When you submit your form the server outputs "GET .. " on the console
<PCiobanita>
yeah but the post stil runs
<PCiobanita>
it does run get but also post. if i were to change the sql with hardcoded number and string it would post it in the database
mostlybadfly has quit [Quit: Connection closed for inactivity]
<phaul>
it runs post if you see POST in your server logs. You don't - correct?
<PCiobanita>
i do
<PCiobanita>
i see post
<PCiobanita>
in log
<phaul>
ok.
davidw has quit [Ping timeout: 268 seconds]
<phaul>
the main issue is that the way forms work is that you need a form per question. you have a single form and many submit buttons in it, one per question. The way to do this is to have a separate form per question, and the submit button in the form would send up the data from the form that it is in
<PCiobanita>
but is a loop it creates a seperate from for each question
<phaul>
no, the loop is inside the single form tag
<PCiobanita>
if injects array with question and for each it ptints the question the adds a textarea and then add a submit button
<PCiobanita>
not the answer loop but the other one
<phaul>
Im talking about the literal <form> tag. that is outside
<PCiobanita>
a bit above is the @poosts loop
<PCiobanita>
the one inside just loops the answers to match it with question id
tdy has joined #ruby
<phaul>
ah Im blind. I take that back.
<PCiobanita>
no worries I am horible in making my coide dr
<PCiobanita>
code dry* is supper messy
orbyt_ has joined #ruby
<phaul>
ok you have a form outside of everything. that causes issues. Please remove that
<PCiobanita>
removed it... i didnt make the erb's to be fair
<phaul>
i removed that form tag from outside and I can confirm the params are correctly sent up to the post handler
<phaul>
the outside post tag screwed up firefox and made the submit a GET request.
<phaul>
you might not be on firefox, so you might see slightly different behaviour
<phaul>
but it was wrong anyway
<PCiobanita>
what would I have to type in the sql inside the answer post. in the save function
<PCiobanita>
answer model sorry
<phaul>
what is the error that you are now getting/
<phaul>
?
<PCiobanita>
undifined method for student answer
<phaul>
read carefully the error report. the word student
<PCiobanita>
NoMethodError at /question/1 undefined method `sudentanswer' for #<Answer:0x00007fbb4e31f158> Did you mean? studentanswer studentanswer=
<phaul>
sudent vs student
<PCiobanita>
oh
<phaul>
our brains are programmed to fix spelling errors for us, it's really hard to spot especially if you wrote it
uplime has quit [Ping timeout: 240 seconds]
<PCiobanita>
i feel like an idiot
<phaul>
dont. its very typical in programming,
<phaul>
happens to everybody
<PCiobanita>
it works now the next issue is how to take the id.. from the first loop
<PCiobanita>
so i can match in the database the answer to the question id
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<PCiobanita>
thank you btw
lucasb has quit [Quit: Connection closed for inactivity]
<phaul>
np. I dont know your background, but what you are working with after 2 weeks is pretty impressive. I would argue that you are maybe progressing too fast. Is this some course exercise? Did you have a programmer background ?
conta has quit [Quit: conta]
<PCiobanita>
no i just enroled into a bootcamp.. so i can learn programing
<PCiobanita>
and it has 2 courses sql and ruby so I am trying to develop a app that checks querys automatically. I think it has evreything login, a bit of front end backend.. so i thought is good to practice all these diff parts
sagax has joined #ruby
<PCiobanita>
<phaul> if u are still here can u tell me how should i go to take the post.id from the first loop on each submit
<phaul>
let me think
<PCiobanita>
i wanna match the answer with the questionid
orbyt_ has joined #ruby
<PCiobanita>
ok
tdy has quit [Ping timeout: 250 seconds]
hutch has quit [Ping timeout: 250 seconds]
<phaul>
I think this bit is conceptually broken: <% if(post.id == answer.id) %>
<phaul>
<%= answer.studentanswer%>
<phaul>
<% end %>
<phaul>
the post is the question. the answer might be filled in might not, but shouldn't it be something like post.id == answer.post_id ? what is the id column of the answer table?
<PCiobanita>
the reason is like this is beacuse i would like a student to be able to go back to the test and have the answers saved. so if the questionid from question table matches with questionif from answers place the answer there
<phaul>
yeah, I get that part Im confused by the ids being equal? Is the answer.id a reference into post ? ( if so it's better to call it post_id )
dinfuehr has quit [Quit: ZNC 1.6.6+deb1ubuntu0.1 - http://znc.in]
<PCiobanita>
answer.id is question id.. which is foreign key of question.id from questiontable
<PCiobanita>
answer and question have id primary and foreign key
<phaul>
right. usually ppl call foregin keys, like <other_table>_id, it just confused me that's all. but now I get it
am0123 has joined #ruby
am0123 has quit [Remote host closed the connection]
<phaul>
you could have a hidden form input with the id encoded in its value.