diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 9434edde..0b629c0d 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -8,7 +8,12 @@ def search return redirect_to feed_posts_path if params[:q].blank? index - @posts = @posts.search(params[:q]) + @posts = @posts.search(params[:q]).to_a + render :index + rescue ActiveRecord::StatementInvalid => e + raise(e) unless e.cause.is_a?(SQLite3::SQLException) + + flash.now[:search_failed] = e.cause.message render :index end diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index b00995e0..ea721316 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -6,12 +6,16 @@ <%= @feed.name %>

- <%= form_with url: search_feed_posts_path(@feed), method: :get, local: true, class: "flex mt-6 gap-4" do |form| %> + <%= form_with url: search_feed_posts_path(@feed), method: :get, local: true, class: "flex mt-6 mb-4 gap-4" do |form| %> <%= form.text_field :q, value: params[:q], class: "shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 rounded-md" %> <%= form.submit "Search posts", name: nil, class: "inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %> <% end %> + <%= tag.p(class: "mt-2 border-l-2 border-red-500 bg-red-50 pl-4 py-2 rounded") do %> + Search Failed
+ <%= flash[:search_failed] %> + <% end if flash.key?(:search_failed) %> -