表单字段不会保存到数据库中 - ruby​​ on rails

时间:2017-04-24 20:42:43

标签: ruby-on-rails form-submit

我在这里有一个表单https://pastebin.com/JfXr054y

routes.rb我有

resources :landslides, only: [:new, :create, :index]

landslides_controller.rb我有

  def new
    @landslide = Landslide.new(landslide_params)

    @landslide.save
    render plain: @landslide.inspect
  end

def landslide_params
  params.require(:landslide).permit(:total_id, :year_id, :start_date, :end_date, :day_number, :continent, :country, :location, :type, :admin_level, :new_lat, :new_long, :mapped, :spatial_area, :fatalities, :injuries, :notes, :sources)
end

为什么表单没有保存到表格中?

1 个答案:

答案 0 :(得分:1)

create是执行 def new @landslide = Landslide.new end def create @landslide = Landslide.new(landslide_params) if @landslide.save render plain: @landslide.inspect else render :new end end 的错误方法。应该在name

中完成
id

此外,您的表单看起来不对。返回的参数中表单数据的位置取决于控件的%input#location.form-control{:type => "Location"} 字段,而不是%input#landslide_location.form-control{:type => "text", :name => "landslide[location]"}

而不是

from multiprocessing import Manager
from threading import Thread
from concurrent.futures import ProcessPoolExecutor


class QueueSplitter(object):
    def __init__(self, queues=[]):
        self.queues = queues

    def append(self, q):
        self.queues.append(q)

    def put(self, obj):
        for q in self.queues:
            q.put(obj)

    def close(self):
        self.queues = []
        self.done = True


class IterQueueSplitter(QueueSplitter):
    def __init__(self, it, sentinel=None, queues=[]):
        self.it = it
        self.sentinel = sentinel
        self.queues = queues

    def send(self):
        try:
            self.put(next(self.it))
        except StopIteration:
            self.put(self.sentinel)
            self.close()


def serve(server):
    while not hasattr(server, 'done'):
        server.send()


def consume(me, q):
    for v in iter(q.get, None):
        print('consumer %d: %d' % (me, v))


def repeatabunch(n):
    for i in range(100):
        yield n


if __name__ == '__main__':
    with Manager() as man, ProcessPoolExecutor(4) as ex:
        consumers = []
        producers = []
        servers = []
        for i in range(8):
            queue = man.Queue()
            consumer = ex.submit(consume, i, queue)
            consumers.append(consumer)
            server = IterQueueSplitter(repeatabunch(i))
            server.append(queue)
            servers.append(server)
            producers.append(Thread(target=serve, args=[server]))
        for t in producers:
            t.start()
        for t in producers:
            t.join()
        for consumer in consumers:
            consumer.result()

我希望看到

{{1}}