Answer the question
In order to leave comments, you need to log in
Why in RoR from the edit form to the update method no parameters are passed, except for params[:id] ???
REST controller. Rails version 4.
No parameters are passed to the update method from the edit form, except for id.
# PATH/PUT /products/1
def update
@product = Product.find_by(title: params[:title])
if @product
render text: "Есть"
else
render text: "Нету"
end
end
def product_params
params.require(:product).permit(:title)
end
Answer the question
In order to leave comments, you need to log in
First, don't use all those automatic finders (find_by, find_byt_title...). Use either just find (by id) or already Second, you need to debug
either where('...').first
byebug or pry or, if you quickly check the value, you do:
For example, to see what and how is passed to params
But it is desirable to radically reconsider the approach of debugging.
PS What is strong params (params.require) also understand, this is an important feature.
In your case, add, don't add, it won't work that way. You have made the product_params method, this is how it should be called:@product = Product.where(product_params)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question