Using a Method from Controller in Another Rails -
i using elasticsearch on rails 4 app search through articles.
however, when article not found redirects page alerts user no results found, , allows request page. instead of saying "no results found" want "no results ______ found" in takes search bar query.
i have defined method in articles_controller in order query won't show on page since "no results page" uses different controller.
what best way pull method onto controller or view in case? having trouble finding straight forward answer trying do. thank much.
articles_controller:
def index if params[:query].present? @articles = article.search(params[:query], misspellings: {edit_distance: 1}) else @articles = article.all end if @articles.blank? return redirect_to request_path end get_query end private def get_query @userquery = params[:query] end
new.html.erb (view "no results found" page. uses different controller articles page):
<body class="contactrequest"> <div class="authform" style="margin-top:15px"> <%= simple_form_for @request, :url => request_path |f| %> <h3 style = "text-align:center; color:red;">no results found. <%= @userquery %></h3> <h1 style = "text-align:center; color:black;">request page</h1> <h5 style = "text-align:center; color:black; margin-bottom: 25px;">our experts gather information,<br> , have page asap!</h5> <%= f.error_notification %> <div class="form-group"> <%= f.text_field :email, placeholder: 'email', :autofocus => true, class: 'form-control' %> </div> <div class="form-group"> <%= f.text_field :subject, placeholder: 'item / page requested', class: 'form-control' %> </div> <div class="form-group"> <%= f.text_area :content, placeholder: 'any additional details...', class: 'form-control', :rows => '5' %> </div> <%= f.submit 'request it', :class => 'btn btn-lg btn-danger btn-block' %> <% end %>
as can see i've tried calling @userquery method display on view page, doesn't show since it's defined on different controller. recommendations awesome.
i suggest render results , no results same controller/view. nice clean way partials. view like:
<% if @articles.blank? %> <%= render 'no_results' %> <% else %> <%= render 'results' %> <% end %>
then, create _no_results.html.erb
, populate current new.html.erb
contents , same nominal results page (with partial _results.html.erb
).