jeudi 30 juin 2016

Rails: How to insert and display new data only when click link without form


Is it possible to insert new row and display it when just click link without inputting form? I'd like to insert and display new data in the following table when click the link. I'm not care whether reload the page or not. schema create_table "rooms", force: :cascade do |t| t.integer "schedule_id" t.integer "day", default: 1 ... For example, the following data exists in the rooms table. id | schedule_id | day | 12 | 34 | 1 | insert the data after clicking link (same schedule_id, but increment day) id | schedule_id | day | 12 | 34 | 1 | 13 | 34 | 2 | model schedule.rb class Schedule < ActiveRecord::Base belongs_to :user has_many :rooms, inverse_of: :schedule, dependent: :destroy has_many :amounts, inverse_of: :schedule, dependent: :destroy accepts_nested_attributes_for :rooms, allow_destroy: true ... room.rb class Room < ActiveRecord::Base belongs_to :schedule, inverse_of: :rooms has_many :events, inverse_of: :room, dependent: :destroy has_many :amounts, inverse_of: :room, dependent: :destroy accepts_nested_attributes_for :events, allow_destroy: true default_scope -> { order(day: :asc) } ... view I'd like to add the link in schedules/_schedule.html.erb It has the followings; ... <% schedule.rooms.each do |r| %> <div class="day">Day <%= r.day %></div> ... Is it possible to insert and display new data when only click the link without inputting form? It would be appreciated if you could give me any suggestion.

Aucun commentaire:

Enregistrer un commentaire