Pergunta

I'm having trouble asking the right question I think. From my view, the form asks the user to select a number 6 - 10. Once the user submits the number, the controller uses that number to in a comparison (if/else).

I'm having trouble finding a way to get that 6 - 10 value. So I defined a value, @test_rand_variable, in my model.

attr_accessible :test_rand_variable

And now I'm trying to find a way such that this would work:

<%= form_tag({controller: "subjects", action: "randomize"}, method: "post") do %>
    <div class="span6 offset3 center">
        <div>
            Enter Group Size: 
            <%= select @test_rand_variable,
            [['',nil],
            ["6",6],
            ["7",7],
            ["8",8],
            ["9",9],
            ["10",10]] %>

I'm also unsure on how to access that variable, so maybe thats the reason I'm not seeing the value. Here's an example of what I'm trying:

params[@test_rand_variable] >= 6

If anyone has some literature on this, or any help at all, I would really appreciate it.

Foi útil?

Solução

Is test_rand_variable a column in your database?

If not you want to use attr_accessor: instead, that will allow the variable to be passed through as follows:

<%= form_tag({controller: "subjects", action: "randomize"}, method: "post") do %>
    <div class="span6 offset3 center">
        <div>
            Enter Group Size: 
            <%= select_tag "select_rand_variable",
            [['',nil],
            ["6",6],
            ["7",7],
            ["8",8],
            ["9",9],
            ["10",10]] %>

This should then be passed to the controller as params[:select_rand_variable]

Hope this helps, it's been a while since I played around with form_tags

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top