This a dumb question but even after some research i can’t fix this problem.
I have a form in one of my view that allow me to get a value from a visitor.
I’m trying to get that value submitted in the form in my controller. And I don’t understand
why but it seems that the only value that I get with this code is 0..
I think I don’t use the correct synthax.
Here is my code from the view :
.mybox
%p Tentative de vote.
= @useful_tool.nbofrate
= @useful_tool.nbtotal
= @useful_tool.newrate
= form_for(@useful_tool) do |f|
= f.select :newrate, [['1 étoile', 1],['2 étoiles', 2],['3 étoiles', 3],['4 étoiles', 4],['5 étoiles', 5]]
= f.submit
Here is my code from my controller :
def update
@useful_tool = UsefulTool.find_by_slug!(params[:id])
@useful_tool.nbofrate = @useful_tool.nbofrate + 1
value = params[:newrate]
@useful_tool.nbtotal += value.to_i
@useful_tool.rating = @useful_tool.nbtotal / @useful_tool.nbofrate
update! { url_for(action: "index") }
end
Because apparantly value must be nil I don’t understand why.
Any help would be very apreciate. Thanks a lot.
try to use
to_s.to_dwith nbtotal and value.or you can explicitly check for nil