Answer the question
In order to leave comments, you need to log in
How to leave the user on the page after submitting the form?
There is a form, after accepting which, there is a redirect to the path of the name of the model / controller, which I do not need (redirect). The form is on the main one, everything is sent to the database, only you need to make sure that there is no redirection, and when Order.count is changed, jquery code is executed, and the page is not reloaded. What we have:
1. Form. I don't think it will help solve the problem. Just a form with two text fields and a button.
2. A controller that is both root and creates a new Order
class OrdersController < ApplicationController
def mainp
end
def help
end
def list
@order = Order.all
end
def new
@order=Order.new
end
def create
@order = Order.new(order_params)
if @order.save
#
else
#
end
end
def order_params
params.require(:order).permit(:name, :phone)
end
end
class CreateOrders < ActiveRecord::Migration
def change
create_table :orders do |t|
t.string :name
t.string :phone
t.timestamps null: false
end
end
end
class AddIndexToOrdersPhone < ActiveRecord::Migration
def change
add_index :orders, :phone, unique: false
end
end
$(document).ready(function(){
$("#success-b").on("click", function(){
if (/*<%= assert_difference 'Order.count'*/) {
console.log("1")
} else {
console.log("2")
}
})
})
def create
@order = Order.new(order_params)
if @order.save
"JQUERY CODE" без перезагрузки страницы
else
#
end
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question