Note that there are some explanatory texts on larger screens.

plurals
  1. PORails - session request is nil error
    primarykey
    data
    text
    <p>I have a method that I want to execute some search logic, and then save a Search object that has the searched string and user id of the person who did the search.</p> <p>The search/save logic seems to be working fine otherwise, but when I try to get the current user (using a method from the application controller) it throws a runtime error that has to do with the session:</p> <pre><code>ActionController::Metal#session delegated to @_request.session, but @_request is nil: #&lt;SearchController:0x1038e32e0 @action_has_layout=true, @view_context_class=nil, @_status=200, @_headers={"Content-Type"=&gt;"text/html"}&gt; </code></pre> <p>Here's the method in the search controller:</p> <pre><code>class SearchController &lt; ApplicationController ... def factualsearch(search) if search searchquery = Search.new # this causes the error if current_user searchquery.user = current_user end searchquery.search_string = search searchquery.save ... end @results end </code></pre> <p>end</p> <p>Here's the current_user method I'm trying to call from my application controller:</p> <pre><code>def current_user return unless session[:user_id] @current_user ||= User.find_by_id(session[:user_id]) end helper_method :current_user </code></pre> <p>Here's the pages controller where I'm calling the method:</p> <pre><code>class PagesController &lt; ApplicationController ... def search searchcontrol = SearchController.new @results = searchcontrol.factualsearch(params[:search]) end ... </code></pre> <p>end</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload