W
W
WEB_champion2014-11-03 12:01:41
Ruby on Rails
WEB_champion, 2014-11-03 12:01:41

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

Why is it not receiving (not transmitting)??? I also tried like this:
def product_params
      params.require(:product).permit(:title)
end

From this method too does not accept.
Please tell me how to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2014-11-03
@WEB_champion

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 question

Ask a Question

731 491 924 answers to any question