Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选择一个值并在文本字段+;Jquery和RubyonRails_Jquery_Ruby On Rails_Jquery Selectors_Textfield - Fatal编程技术网

选择一个值并在文本字段+;Jquery和RubyonRails

选择一个值并在文本字段+;Jquery和RubyonRails,jquery,ruby-on-rails,jquery-selectors,textfield,Jquery,Ruby On Rails,Jquery Selectors,Textfield,你能帮我吗 我是RubyonRails的新手,当我选择一个选项时,我很难在表单中显示信息。有人告诉我,我需要使用Jquery,尽管我还没有让它工作 我需要选择一个月,在文本_字段(meta)中,我需要显示方法结果,但我不知道我还需要做什么 我有这个: class Logind < ActiveRecord::Base def mejora(mes) if mes == 1 "#{estado}".parameterize else @meta =

你能帮我吗

我是RubyonRails的新手,当我选择一个选项时,我很难在表单中显示信息。有人告诉我,我需要使用Jquery,尽管我还没有让它工作

我需要选择一个月,在文本_字段(meta)中,我需要显示方法结果,但我不知道我还需要做什么

我有这个:

class Logind < ActiveRecord::Base

  def mejora(mes)
    if mes == 1
    "#{estado}".parameterize
    else 
      @meta = "#{meta}".to_i          # @meta -> variable de instancia
      @estado = "#{estado}".to_i
      @peorE = "#{peorE}".to_i
      puts @mejora = (@estado + ((@meta - @peorE)/11))
    end
  end
}))


谢谢你的帮助

你是说这个结果“@mejora=(@estado+(@meta-@peorE)/11”)需要出现在“meta”字段中吗?如果是这样,你必须在“change”函数中发出Ajax请求,这样当用户选择月份时,Ajax请求将被触发,在这里你可以找到如何发出Ajax请求。您还需要以某种方式公开“mejora”,为此,您需要一个控制器,在控制器中,您需要调用该方法并以JSON格式返回结果。祝你好运,我的朋友,继续阅读,不要放弃。也许,如果你不想在ruby中做任何有趣的事情,你甚至不需要提出ajax请求,看起来你只是在做一些基本的数学。在这种情况下,在“change”函数中进行计算,并更新你的#mes字段。你是说这个结果“@mejora=(@estado+(@meta-@peorE)/11”)需要出现在“meta字段”中吗?如果是这样,你必须在“change”函数中发出Ajax请求,这样当用户选择月份时,Ajax请求就会被触发,在这里,您可以找到如何发出ajax请求。您还需要以某种方式公开“mejora”,为此,您需要一个控制器,在控制器中,您需要调用该方法并以JSON格式返回结果。祝你好运,我的朋友,继续阅读,不要放弃。也许,如果你不想在ruby中做任何有趣的事情,你甚至不需要提出ajax请求,看起来你只是在做一些基本的数学。在这种情况下,在“change”函数中进行计算,并更新#mes字段。
class LogindsController < ApplicationController

  # GET /loginds/new
  def new
    @logind = Logind.new 
    @logind.mejora(:mes)

  end
        <%= form_for(@logind) do |f| %>
          <% if @logind.errors.any? %>
            <div id="error_explanation">
              <h2><%= pluralize(@logind.errors.count, "error") %> prohibited this logind from being saved:</h2>

              <ul>
              <% @logind.errors.full_messages.each do |message| %>
                <li><%= message %></li>
              <% end %>
              </ul>
            </div>
          <% end %>

          <div class="field" id="meta">
            <%= f.label :Meta %><br>
            <%= f.text_field :meta %>
          </div>
        <div class="row">
            <div>
                <section class="col-sm-4">
                    <%= form_for(@logind) do |f| %>
                        <% if @logind.errors.any? %>
                            <div id="error_explanation">
                                <h2><%= pluralize(@logind.errors.count, "error") %> prohibido este registro para ser guardado:</h2>

                                <ul>
                                <% @logind.errors.full_messages.each do |message| %>
                                    <li><%= message %></li>
                                <% end %>
                                </ul>
                            </div>
                        <% end %>

                        <% mes = {:Enero => 1, :Febrero => 2, :Marzo => 3, :Abril => 4, :Mayo => 5, :Junio => 6, :Julio => 7, :Agosto => 8, :Septiembre => 9, :Octubre => 10, :Noviembre => 11, :Diciembre => 12} %>
            <div class="field"> 
                    <% lista = mes %>
                    <%= f.label :Mes %><br>
                    <%= f.select :mes, lista, {include_blank: "- Elegir mes -"}, {:class => 'logbymonth'} %>
            </div>
                    <% end %>
                </section>
            </div>

            <div class="col-sm-8">
                <section class="containerWaterMark">
                    <h1>Nuevo registro de indicador</h1>

                    <%= render 'form' %>
                </section>
            </div>

            <div>
                <%= link_to 'Atrás', loginds_path, class:"btn btn-default" %>
            </div>
$(document).ready(function(){
$('.logbymonth').change(function(){
    var month = $('.logbymonth').val();
    $('#mes').val('month');
});