Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent error when current_user is called without refetch: true #190

Closed
navjeetc opened this issue Jun 6, 2015 · 11 comments
Closed

Silent error when current_user is called without refetch: true #190

navjeetc opened this issue Jun 6, 2015 · 11 comments

Comments

@navjeetc
Copy link

navjeetc commented Jun 6, 2015

I am this error on starting in dev mode on running rackup command . I am using Rails 4.2 and ruby 2.1.5

rackup sync.ru

Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:9292, CTRL+C to stop
Rack::Lint::LintError: Status must be >=100 seen as integer
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/lint.rb:20:in assert' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/lint.rb:620:incheck_status'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/lint.rb:51:in _call' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/lint.rb:37:incall'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/showexceptions.rb:24:in call' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/commonlogger.rb:33:incall'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/chunked.rb:54:in call' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/content_length.rb:15:incall'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/thin-1.6.3/lib/thin/connection.rb:86:in block in pre_process' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/thin-1.6.3/lib/thin/connection.rb:84:incatch'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/thin-1.6.3/lib/thin/connection.rb:84:in pre_process' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/thin-1.6.3/lib/thin/connection.rb:53:inprocess'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/faye-websocket-0.9.2/lib/faye/adapters/thin.rb:40:in process' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/thin-1.6.3/lib/thin/connection.rb:39:inreceive_data'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/faye-websocket-0.9.2/lib/faye/adapters/thin.rb:44:in receive_data' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:inrun_machine'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in run' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/thin-1.6.3/lib/thin/backends/base.rb:73:instart'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/thin-1.6.3/lib/thin/server.rb:162:in start' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/handler/thin.rb:19:inrun'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/server.rb:286:in start' /Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/lib/rack/server.rb:147:instart'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/gems/rack-1.6.1/bin/rackup:4:in <top (required)>' /Users/navjeetc/.rvm/gems/ruby-2.1.5/bin/rackup:23:inload'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/bin/rackup:23:in <main>' /Users/navjeetc/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:ineval'
/Users/navjeetc/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `

'
127.0.0.1 - - [06/Jun/2015:14:16:17 -0400] "GET /faye?message=%5B%7B%22channel%22%3A%22%2Fmeta%2Fhandshake%22%2C%22version%22%3A%221.0%22%2C%22supportedConnectionTypes%22%3A%5B%22websocket%22%2C%22eventsource%22%2C%22long-polling%22%2C%22cross-origin-long-polling%22%2C%22callback-polling%22%5D%2C%22id%22%3A%221%22%7D%5D&jsonp=jsonp364 HTTP/1.1" 500 82333 0.0314

@breim
Copy link

breim commented Jun 7, 2015

Hi!
Faye dont work in development mode, run it on production mode.
Start your app with RAILS_ENV=production rails server
Start a faye server with rackup sync.ru -E production
Reference: faye/faye#25

@navjeetc
Copy link
Author

navjeetc commented Jun 7, 2015

I tried starting faye in production mode. Now I do see in the log a call being made to the partial but it is followed by an error call as shown below and it does not update my page which is open in another tab.

Rendered sync/projects/_project_row.html.erb (3.7ms)
undefined method `env' for nil:NilClass

@navjeetc
Copy link
Author

navjeetc commented Jun 8, 2015

Looks like everything works fine when I use pusher but not when I use faye. When I start faye in production mode, do I have to start Rails app in production mode also? I have tried Rails app in both dev and production mode but neither seems to update data although I do see a call being made to render the partial. Does that mean the updated state of model is not being passed to partial. I am trying to test update action.

@navjeetc
Copy link
Author

navjeetc commented Jun 8, 2015

I did some more digging and looks like my partial has a call to current user which causes undefined method `env' for nil:NilClass error on line 135 in
https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.eb
The line is
request.env['warden']
and request object is nil
Should the request object be nil?

Just to be clear when there is no call to current_user in view, the update works with Pusher but not with Faye.

@ajb
Copy link
Collaborator

ajb commented Jul 5, 2015

Hey @navjeetc, sorry for the delay in response.

If you need to call current_user in your view, you should use "refetch partials" so that the view gets rendered in the context of the correct user.

@ajb ajb changed the title cannot start in development mode Silent error when current_user is called without refetch: true Jul 5, 2015
@navjeetc
Copy link
Author

navjeetc commented Jul 6, 2015

So adding refetch: true to partial call, did render the partial with updated value but the partial was rendered twice hence listing two identical rows. Not sure why.

@navjeetc
Copy link
Author

navjeetc commented Jul 6, 2015

And faye still does not work even when rails and rack are started in production mode.

@aruprakshit
Copy link
Contributor

@navjeetc How did you resolve it finally ? I am having an identical issue of getting duplicate records.

@navjeetc
Copy link
Author

No I did not

@ajb
Copy link
Collaborator

ajb commented Feb 6, 2016

Moving to #214

@ajb ajb closed this as completed Feb 6, 2016
@aguayma
Copy link

aguayma commented Nov 8, 2016

Was anyone able to resolve this issue? Ran with pusher and faye and I am still receiving the following error:

method=POST path=/messages format=js controller=MessagesController action=create status=500 error='ActionView::Template::Error: undefined method `env' for nil:NilClass' duration=70.15 view=0.00 db=12.97
15:48:48 server.1 |
15:48:48 server.1 | NoMethodError - undefined method `env' for nil:NilClass:
15:48:48 server.1 |   devise (4.2.0) lib/devise/controllers/helpers.rb:141:in `warden'
15:48:48 server.1 |   devise (4.2.0) lib/devise/controllers/helpers.rb:124:in `current_user'
15:48:48 server.1 |   actionpack (4.2.7.1) lib/abstract_controller/helpers.rb:67:in `current_user'
15:48:48 server.1 |   app/views/sync/messages/_message_row.html.erb:11:in `_app_views_sync_messages__message_row_html_erb___4026068312585040076_70129917733380'

The message object is being created, so when page refreshes the new message is there.

Here is a look at the controller:

def create
    @message = Message.new(message_params)
    respond_to do |format|
      if @message.save
        sync_new @message, scope: @conversation
        format.html { render :nothing => true, :status => 200 }
        # format.json { render :show, status: :created, location: @message }
        format.js { render :nothing => true, :status => 200 }
      else
        format.html { redirect_to influencer_path(id: current_user.influencer.id) }
        format.json { render json: @message.errors, status: :unprocessable_entity }
      end
    end
  end

calling the partials:

<div style='border-bottom:thin solid #f2f2f2'>
  <% @messages.each do |message| %>
  <%= sync partial: 'message_row', resource: message, refetch: true %>
  <% end %>
  <%= sync_new partial: 'message_row', resource: Message.new, scope: @conversation, refetch: true %>
</div>

partial:

<div class='col-xs-12 col-md-12 own-sent-messages'>
  <div class='col-xs-3 col-md-2'>
    <%= link_to image_tag(message.sender.determine_avatar, {class: 'img-responsive img-circle influencer-circular-image'}), message.sender.profession %>
  </div>
  <div class='col-xs-9 col-md-9'>
    <div>
      <%= simple_format(message.body, {class: 'small-text msb-grey-color remove-margin', style: 'font-size:14px'}) %>
    </div>
    <div>
      <p class='large-title msb-grey-color remove-margin'>
        <%= message.created_at.in_time_zone(current_user.influencer.time_zone).strftime("%b %d, %Y") %>
        <%= message.created_at.strftime("%b %d, %Y") %>
      </p>
    </div>
  </div>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants