0

So I am trying to create a web application in ruby rails that runs three stopwatches.

class StopwatchesController < ApplicationController

  def index
   @string1 = "Timer 1"
   @string2 = "Timer 2"
   @string3 = "Timer 3"
   @time_1 = 0
   @time_2 = 0
   @time_3 = 0
   gon.myNum1 = @time_1
   gon.myNum2 = @time_2
   gon.myNum3 = @time_3
 end

I'm really new at this and am trying to make it so I can have the user edit the values for all @variables in the View component. Sorry if anything comes off as atrocious in the code.

edit: I got read the comments about me not being clear, my bad guys and thanks for the feedback (: So in my app\views\stopwatches\index.html.erb I have the following code:

  <h4><%= @string1 %></h4><br>
  <div class="clock_1">
  <script type="text/javascript">
    var clock = $('.clock_1').FlipClock(gon.myNum1, {
    countdown: true,
        clockFace: 'MinuteCounter',
    });


This is pretty much a gem for one of the clocks, where @string1 is the name given by the user while gon.myNum1 will be a numerical value for the time. My problem is pretty much that I don't know how to create a page or form that can have the user change the contents of the variable mentioned.

2
  • 3
    what you try to solve? Commented Dec 5, 2016 at 4:19
  • 3
    Hi and welcome to Stack Overflow. It's kinda unclear what you need from us. What happened when you ran this? What did you observe happening? what did you expect to happen? what have you tried to fix the problem? etc :) Commented Dec 5, 2016 at 4:29

2 Answers 2

1

The MVC architecture is designed so that you can pass data from a controller to a view. However, you cannot go backwards, from the view to the controller.

Sign up to request clarification or add additional context in comments.

Comments

0

So if you want the user to be able to edit the variables in the controller (ie. pass data from the view to your server), you are going to need a Form for each variable you want the user to be able to change via a POST request. Rails has several form helpers which make this fairly simple. You can then grab this data passed to the controller via the params.

I do think the other questioners are correct though and you need to get a better idea of what it is exactly you are trying to accomplish and how a MVC framework like Rails can help you with this.

This might help you: https://betterexplained.com/articles/intermediate-rails-understanding-models-views-and-controllers/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.