Note that there are some explanatory texts on larger screens.

plurals
  1. POrescue_from NoMethodError
    primarykey
    data
    text
    <p>Having problems figuring this out.</p> <p>trying to do a </p> <pre><code>rescue_from NoMethodError, :with =&gt; :try_some_options </code></pre> <p>But its not working.</p> <p>EDITED: For testing I'm doing a simple redirect</p> <pre><code>def try_some_options redirect_to root_url end </code></pre> <p>EDITED 2: Sample of my controller. Added (exception) as recommended below.</p> <p>I know the reason I'm getting the error. Using Authlogic and authlogic_facebook_connect plugin. When user is created from the facebook plugin the "MyCar" model, which is associated with a user is not created like it normally is created if a user registers locally. Since I do call on the user model and reference the users car throughout different parts of the site, I would like to do something like what you see below and eventually put it in my application_controller.</p> <pre><code>class UsersController &lt; ApplicationController before_filter :login_required, :except =&gt; [:new, :create] rescue_from NoMethodError, :with =&gt; :try_some_options ... def show store_target_location @user = current_user end def create @user = User.new(params[:user]) if @user.save MyCar.create!(:user =&gt; @user) flash[:notice] = "Successfully created profile." redirect_to profile_path else render :action =&gt; 'new' end end ... protected def try_some_options(exception) if logged_in? &amp;&amp; current_user.my_car.blank? MyCar.create!(:user =&gt; current_user) redirect_to_target_or_default profile_path end end ... end </code></pre> <p>EDITED 3: Hacked it for now since I know why the error is showing up, but would like to figure out how to rescue_from NoMethodError</p> <pre><code>class UsersController &lt; ApplicationController before_filter :login_required, :except =&gt; [:new, :create] before_filter :add_car_if_missing def add_car_if_missing if logged_in? &amp;&amp; current_user.my_car.blank? MyCar.create!(:user =&gt; current_user) end end end </code></pre>
    singulars
    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.
 

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