html - Ruby On rails validations -


i new rails.

i have create simple rails page accepts bookid, title , publisher

rails generate scaffold book bookid:string title:string publisher:string

i have written new search.html.erb , defination search books title.

now question how give custom message if book details doesn't exist in database.

ex : gave book name rails doesn't have entry in database

it should give message no such books

you can following:

# controller def search   @books = book.where('title ilike ?', "%#{params[:title]}%") end  # view <% if @books.present? %>   code books <% else %>   no such books <% end %> 

here substitute given title param query , assign found books @books. use variable in views.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -