Hi, this is shirakaba.
This time I would like to review Rails.
I've erased the work I was making at the online school before, so I'm thinking of making it again as a review.
However, the content I write this time has solved the error that occurred in the process of making the application! I would like to write that.
As an aside, I've been chased by something else for a long time and forgot about my important things, my original purpose, and what I enjoyed, so I went back to the starting point and learned the task and programming in parallel. I want to do it while doing it!
I will learn as I like!
※important point Inexperienced and now a beginner studying on his own. It is written for the purpose of outputting what you have learned. Therefore, I think there may be mistakes, but in that case, I would appreciate it if you could see it with warm eyes.
When I tried to create a search function and tried to create a search action on the controller, I made the following description, but the following error occurred.
def search
if params[:content].present?
@book = Book.where(user_id: current_user.id,['title LIKE ? OR author LIKE ? OR label LIKE ?',"%#{params[:content]}%", "%#{params[:content]}%", "%#{params[:content]}%"])
else
@book = Book.none
end
end
When I access the URL, the usual error screen appears ...
syntax error, unexpected ')', expecting => ...]}%", "%#{params[:content]}%"]) ... ^
@book = Book.where(user_id: current_user.id,['title LIKE ? OR author LIKE ? OR label LIKE ?',"%#{params[:content]}%", "%#{params[:content]}%", "%#{params[:content]}%"])
In the terminal
SyntaxError (/Folder name/Folder name/controllers/books_controller.rb:6: syntax error, unexpected ')', expecting =>
...]}%", "%#{params[:content]}%"])
... ^
):
From the conclusion, I solved it by writing where
in two and connecting them.
@book = Book.where(user_id: current_user.id).where('title LIKE ? OR author LIKE ? OR label LIKE ?',"%#{params[:content]}%", "%#{params[:content]}%", "%#{params[:content]}%")
This time it was an error due to a description error, but I had a hard time finding it ... If you investigate the cause properly and think calmly, it may not have taken so long.
Although it is a review, it makes me realize that there is still a lack of training. Besides, this may not be a beautiful way of writing, so I'll investigate it more properly.
In the future, I would like to be able to output any trivial or embarrassing things in this way. Then ~
Recommended Posts