last day (15 days later) » 

4:14 AM
0
Q: Rails survey app with multiple users logged in

Noel MurphyI'm currently working with 2 colleagues on a survey app, and we are almost completed, however we have run into something I would imagine is a common issue. Essentially, when one user interacts with the survey, this action is carried out for all other others. IE John hits next, Mary hits next an...

 
How does the system know who John and Mary are? Are they registering?
 
Their accounts are set up by an admin. I'm using the devise gem. Right now they are just dummy accounts we plugged in manually.
 
The survey should have a user_id then. You need to persist that back-and-forth between controllers and views. Please edit your question to show some code.
 
There is the questions controller. We have user_id attributes from the SQL table, or do you mean an extra attribute? For our application we are having a feature at the end to change any answers given by the user, hence loading the array with question objects from the table, not just accessing them via SQL each time. I guess it's ORM. I also put up the user model.
Still with me John?
 
Yes. What about the view?
 
4:18 AM
Hello?
 
Yes.
 
Hi John
Thanks for sharing your time to help first o fall
of all*
so the view
 
No troubles.
 
It's difficult for me to copy paste as I am remotely connected to the server
and on here in my own OS
I'm just trying to figure out how to open this chat on there
okay got it
<%= stylesheet_link_tag "application.css" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
so as you can see the question being displayed is accessed from the array
s-cube.online:3000
test@test.de 123456
here is the app for you with our dummy login to give you a better perspective
 
FYI, your code is very hard to read. fanarray and anarray are not good variable names. And you should never have globals called a and b.
 
4:23 AM
got it
we only managed this yesterday morning hence the messy array names
and the global name
 
Where does a user START to take a survey?
 
"First form"
on the welcome page sidebar
 
No, what controller action.
 
index
 
QuestionsBasic controller, index action?
 
4:26 AM
yes
 
And that renders the view file you pasted just above?
 
oh sorry, the belongs to line
let me take that back out
but yes
 
OK.
Two things.
Stop using global @@ variables. Those are going to exist for ALL users, so of course when one user does something it's going to affect what another user does.
In your form, you need to have a hidden_field of :user_id with the value of current_user.id -- give me a second to get the exact syntax.
<%= hidden_field_tag(:user_id, current_user.id) %>
However....
I still don't see where you actually save anything to the database. What happens after you ask the last question?
 
sure, thank you, I just changed a few lines we added in, question view is working now
so we are storing question ids with answers and the user id into an array
at the end, the questions and answers will be displayed somehow and allow the user to change any answers they gave
then they will finally be put into an answers table
 
OK.
 
4:34 AM
the whole array, the user id, the question id and the answer
 
Can I tell you an observation? Please don't be offended, this is just my initial impression.
 
shoot
 
It seems like you are more comfortable with C or Perl - and then tried to translate how you would do it in one of those languages into 'equivalent' Ruby code. That's not a good way to do things.
 
I'm amazed you spotted that
I started developing in Java
 
OK. Java is better than C, at least it's OO
 
4:37 AM
I've been working since March with Spring/struts
 
With Ruby, and especially with Rails, you should work with the objects that you have. It's better to pass around actual Question and Answer objects in memory, and then persist them into the DB. Don't put things into arbitrary data structures that you then have to pull apart and shuffle around.
 
I got the feeling the array idea just wasn't right but I didn't know how to do something like this without storing it in something
 
Rails gives you the params hash for passing data from a view to a controller - use it!
 
That is a great tip
That is fantastic
thank you
 
You're welcome. Good luck!
 
4:42 AM
hold on
 
how am I supposed to handle this data at the end if I shouldn't store it in an array?
 
You need to build up the actual Answer (or I guess TmpAnswer) objects and associate them with the User object. Look up the .build() method.
current_user.tmp_answers.build(...stuff from the most recent Q&A...) each time you cycle back to the controller.
Actually, given that you have the tmp_answer thing, you can use .create() and it will store that in the DB right then and there.
 
this answers my next question kind of
because I thought it would be easier to go the array route instead of saving it in the table proactively
so you recommend storing it as soon as it is answered?
 
Since you went a wrote a TmpAnswer model, you should use it.
 
4:46 AM
I agree
one more question
actually it's okay
Thanks so much John
 
have a pleasant day
 
Thx. You too.
 
 
17 hours later…
9:59 PM
Hello John, are you there?
 

last day (15 days later) »