My Facebook Connect Rails application worked earlier today, but seems to have stopped getting the Facebook sessions properly.
I'm using the Facebooker gem to handle the interaction with Facebook. All of a sudden, my application started throwing this exception, both while I was logged in to my Facebook account and while I was logged out (on the actual Facebook site):
WelcomeController#index (ActionView::TemplateError) "Session key invalid or no longer valid"
On line #4 of app/views/welcome/_friends.html.erb
1: <div class="bluebox friends_box">
2: <h3>Friends</h3>
3: <table class="friends_table">
4: <% friends = facebook_user.friends_with_this_app %>
5: <% if friends.any? %>
6: <% friends.each do |friend| %>
7: <tr class="friend_row">
app/views/welcome/_friends.html.erb:4
app/views/welcome/_logged_in_index.html.erb:90
app/views/welcome/index.html.erb:2
<internal:prelude>:8:in `synchronize'
<internal:prelude>:8:in `synchronize'
First of all, make sure that your app is authorized with Facebook by going to the following address in the browser window where you got the exception:
http://www.facebook.com/login.php?api_key=YOUR_APP_KEY&next=RETURN_URL
If you're getting the error after that, more than likely, it has to do with Facebook itself. Sometimes it helps to get the session key out of cookie ("YOUR_APP_KEY" + "_session_key" cookie), but sometimes it doesn't work either.
Related
I am able to login and logout most of the time, but sometimes during logging out I am returned with this error as stated below and I am not logged out.
Can't verify CSRF token authenticity.
User excluded error: #<ActionController::InvalidAuthenticityToken: ActionController::InvalidAuthenticityToken>
It doesn't happen always that I am not able to logout but when I am not able to logout above is the error which I get. I read about it this is what I have done so far. I am using vuejs on my front end and rails on the backend. I am using rails version 5.1.
application_controller.rb
protect_from_forgery with: :exception
application.html.erb
<%= csrf_meta_tags %>
this is the axios request I am making to logout the user
index.vue
logout() {
this.$axios.delete('/users/sign_out').then(function(response) {
console.log("Logged out")
});
}
Please help me resolve this issue
You may need to add the csrf_meta_tags to the request
In your case, the csrf_meta_tags in application.html.erb is not re-rendered.
I made a mistake before migrating a plugin, and have written
flash[:notice] = :label_presta_added
instead of
flash[:notice] = l(:label_presta_added)
I corrected my mistake but it seems that my Redmine Plugin has trashed my Redmine. Even though I delete my plugin a migrate once again, I still get this error:
Started GET "/" for 127.0.0.1 at 2016-06-01 22:21:37 +0200
Processing by WelcomeController#index as HTML
Current user: admin (id=1)
Rendered welcome/index.html.erb within layouts/base (28.1ms)
Completed 500 Internal Server Error in 366ms (ActiveRecord: 116.0ms)
ActionView::Template::Error (undefined method `html_safe' for :label_presta_added:Symbol
Did you mean? html_safe?):
97: <div id="sidebar">
98: <%= yield :sidebar %>
99: <%= view_layouts_base_sidebar_hook_response %>
100: </div>
101:
102: <div id="content">
103: <%= render_flash_messages %>
app/helpers/application_helper.rb:312:in `block in render_flash_messages'
app/helpers/application_helper.rb:311:in `render_flash_messages'
app/views/layouts/base.html.erb:100:in `_app_views_layouts_base_html_erb__4104276684161420982_39604440'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
Can somebody give me a hand here?
Thanks in advance!
This is stored in your session, so usually changing the session secret key will invalidate all sessions and discard any old session data.
You can also try and rescue to clear it out as a one-time deal.
Have you restarted the server? Or you can use flash[:notice] = nil to remove it.
It looks like it throws a html_safe error. Can you see if the method which is rendering the flash is using html_safe? It looks like its coming from there.
Not sure exactly, may be shooting in the dark.
But read these and try may be:
actionview::template::error(undefined method 'html_safe' for nil:NilClass)
http://www.redmine.org/issues/8477
I am using Rails and Devise in a Rails application.
In my code, I am trying to use current_user in layouts/_header.html.erb.
<% Rails.logger.debug("Time is: #{Time.now} - Current User: #{current_user}") %>
When I use Firefox on my MAC to run the application, here's what I have in the log file:
Time is: 2013-06-18 16:21:42 - Current User: #<User:0x007fae442cf020>
When I use Chrome on my MAC to run the application, here's what I have in the log file:
Time is: 2013-06-18 16:20:33 - Current User:
Rendered layouts/_promo_bar.html.erb (3.4ms)
Completed 500 Internal Server Error in 657ms
ActionView::Template::Error (undefined method `email' for nil:NilClass):
27: <div class="promo-bar-box last-right-box">
28: <div class="request-invitation-text">
29: <% Rails.logger.debug("Time is: #{Time.now} - Current User: #{current_user}") %>
30: <% reg_user = user_registered_for_event(current_user.email) %>
app/views/layouts/_promo_bar.html.erb:30:in `_app_views_layouts__promo_bar_html_erb__785786602602486184_70193263335300'
Any ideas?
It looks like you are accessing a page without having logged in yet. If the session isn't set then current_user isn't going to exist and throw an error when trying to access one of its attributes, in this case being the user's email.
If you are logged in, try clearing your session cookie via Devloper Tools (hamburger icon > tools > Developer Tools). And reloading the page.
This Ruby on Rails problem is a bit vexing, as the code works fine locally but not when I push it onto my live server.
I've added a few int columns into a table using a migration and have a few checkboxes to determine whether items of a certain status are displayed on a certain page, eg:
status\page myitems featureditems saleitems
status1 X x x
status2 x x
This works fine locally in a development environment, but when I push the code to my live server the "add new feature" page fails to load with the following error:
Started GET "/admin/statuses/new" for 86.159.115.236 at 2012-08-19 13:39:12 -0400
Processing by Admin::StatusesController#new as HTML
Rendered shared/_validationerror.html.erb (0.0ms)
Rendered admin/statuses/_form.html.erb (2.1ms)
Rendered admin/statuses/new.html.erb within layouts/application (2.2ms)
Completed 500 Internal Server Error in 4ms
ActionView::Template::Error (undefined method `show_my_items' for #<Status:0xb6c1690>):
20: </tr>
21:
22: <tr>
23: <td align="center"><%= f.check_box :show_my_items %></td>
24: <td align="center"><%= f.check_box :show_latest_items %></td>
25: <td align="center"><%= f.check_box :show_featured_items %></td>
26: <td align="center"><%= f.check_box :show_search_results %></td>
app/views/admin/statuses/_form.html.erb:23:in `block in
_app_views_admin_statuses__form_html_erb__566719799_79558060'
app/views/admin/statuses/_form.html.erb:1:in
`_app_views_admin_statuses__form_html_erb__566719799_79558060'
app/views/admin/statuses/new.html.erb:7:in
`_app_views_admin_statuses_new_html_erb__880262090_94647510'
app/controllers/admin/statuses_controller.rb:31:in `new'
In this case 'show_my_items' is one of the fields attached to a status, (represented by page1).
Additionally, on live I can edit a status using the checkbox (but it's int datatype...), but on live, though I can view the edit page and submit without an error, it doesn't actually update the field.
So the columns exist in the database, the code is the same code as I have on live, but the error only happens on the live server. Same version of Rails on both (3.1.0.rc8), ruby versions slightly different (local: 1.9.2p320, live: 1.9.3p194).
No idea what's going on...
Just to be sure, did you run the migration on your server in production mode?
$ RAILS_ENV=production rake db:migrate
Well the problem seems to be that Passenger did not start correctly. Either it takes longer than I thought or something else went wrong, but having restarted passenger again it worked fine.
I'm running Rails 3.1.1 and getting an odd bug. In development (haven't yet tried pushing to production with it) I'm occasionally getting routing errors in my controller or in my mailer template when it tries to generate a url for a newly created record. This happens even though the record is created successfully and appears to have nothing to do with the record properties (I can recreate a record with the exact same params right after and not get the error, it seems totally random when it happens).
It seems to happen maybe one in 10 times, though I can't say I ever saw an incident of it happening before I added the mailer action.
There's one more potentially complicating factor: I'm using an encryption method to obfuscate the record's id in its URL, but this is otherwise working without a hitch. To do this I adapted the method discussed here
It seems to me like the URL's not generated in time for the link_to call some of the time... But that doesn't make much sense to me. I didn't think race conditions were something I needed to worry about here.
Here are my error logs when this happens in the controller (when the params don't call for an email to be generated):
ActionController::RoutingError (No route matches {:action=>"show", :controller=>"watch_lists", :id=>#<WatchList id: 195, title: "sfdsfd", created_at: "2012-03-19 05:18:46", updated_at: "2012-03-19 05:18:46", public_list: false>}):
app/controllers/watch_lists_controller.rb:72:in `block (2 levels) in create'
app/controllers/watch_lists_controller.rb:56:in `create'
And here's when it happens in the mailer template (when the params do call for an email to be generated before the render command):
Rendered watch_list_mailer/share_notification.html.erb (3.2ms)
Completed 500 Internal Server Error in 113ms
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"watch_lists", :id=>#<WatchList id: 210, title: "sdggsgsg", created_at: "2012-03-19 05:47:17", updated_at: "2012-03-19 05:47:17", public_list: true>}):
20: <% end %>
21: <% end %><br>
22: <br>
23: Here's a link to your WatchList: <%= link_to #wl.title, watch_list_url(#wl) %><br>
24: <br>
25: Enjoy!
26: </p>
app/views/watch_list_mailer/share_notification.html.erb:23:in `_app_views_watch_list_mailer_share_notification_html_erb___1391186431365383285_70156615518000'
app/mailers/watch_list_mailer.rb:12:in `share_notification'
app/controllers/watch_lists_controller.rb:124:in `share_notification'
app/controllers/watch_lists_controller.rb:68:in `block (2 levels) in create'
app/controllers/watch_lists_controller.rb:63:in `each'
app/controllers/watch_lists_controller.rb:63:in `block in create'
app/controllers/watch_lists_controller.rb:56:in `create'
EDIT: Upon further testing, this appears to happen regardless of whether I include the mail task. It seems most likely spurred by the obfuscation of the links. It's possible that the encoding of the links has something to do with it (I had to make sure to URI-escape them to prevent slashes in the wrong places elsewhere in my code). I'll investigate this futher and report back.
It was a problem with the id encryption creating invalid links occasionally and me failing to account for that in early enough in the process.
In lib/obfuscate.rb
def uri_encrypt(value)
URI.escape(self.encrypt(value), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end
In my model
def to_param
uri_encrypt(id)
end