As the question I ask, now I can easily use devise_invitable module in rails app. However, it is hard to migrate to angular js.
I'm trying to use $http.post with url '/users/invitation.json' to trigger the invitation on the server side.
$scope.inviteUser = ->
$http.post('/users/invitation.json',
email: $scope.email
).success (data) ->
_log "successful"
The log file shows that
Started POST "/users/invitation.json" for 127.0.0.1 at 2014-10-24 03:48:49 +1100
Processing by Devise::InvitationsController#create as JSON
Parameters: {"email"=>"sample#mail.com", "invitation"=>{"email"=>"sample#mail.com"}}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Completed 422 Unprocessable Entity in 3ms (Views: 0.1ms | ActiveRecord: 0.3ms)
I can figure out that the problem could be the credential. The params apparently miss
"authenticity_token"=>"MEAh9r7vD8cUxXQH9+qnjykHKV8OeC+fvuNW6Whsewg="
But don't know how to fix it. In plain rails app, every thing goes well. I can post email to user_invitation_path to invite new user.
And I'm really new to angular js, could any one help me on it?
I figure out what wrong with my code after several hours. There are 2 problems in the code. Firstly, I should add csrf manually, which should be
myAngularApp.config([
"$httpProvider", function($httpProvider) {
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
}
or just one simpler approach is use a gem
# Gemfile
gem 'angular_rails_csrf'
Secondly, in console, I can use User.invite!(:email => "123#example.com") to send the invitation, that because the email has been wrapped as an attribute in a User object. So in $http request, we cannot directly use email as a parameter.
$scope.inviteUser = ->
user = {
email: $scope.email
}
$http.post('/users/invitation',
user: user
)
Finally everything works well!!
Related
I set up omniauth-password exactly as shown here:
https://github.com/namick/omniauth-password
I, however, get an invalid_credentials error every time I try to sign in. Now, there are no users in my database so it should be creating them right? I'm kind of confused where registration fits into this.
The problem is that my controller is not even being called. Here are the logs.
(password) Callback phase initiated.
(password) Authentication failure! invalid_credentials encountered.
Started POST "/auth/password/callback" for 127.0.0.1 at 2012-12-05 02:34:05 -0800
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'asd#asf.comssdf' LIMIT 1
Started GET "/auth/failure?message=invalid_credentials&strategy=password" for 127.0.0.1 at 2012-12-05 02:34:05 -0800
Processing by SessionsController#failure as HTML
Parameters: {"message"=>"invalid_credentials", "strategy"=>"password"}
Rendered text template (0.0ms)
Completed 200 OK in 16ms (Views: 15.4ms | ActiveRecord: 0.0ms)
Any help appreciated!
not quite answering your specific problem with omniauth-password but,
have you considered using omniauth-identity?
It's a database-based strategy that used username (or email) and password credentials, and there is a Railscast of it.
And: I succesfuully made it work with other strategies.
Omniauth-identity: https://github.com/intridea/omniauth-identity
Railscast: http://railscasts.com/episodes/304-omniauth-identity
I'm having a problem with remote links in IE, and I need to get it up & running soon cause the deadline is today :S
The problem is that we're using AJAX to make a remote call to an action and eval the returned javascript.
When making the call using Firefox for example it's working fine, if I do it in IE, the response is made as HTML request.
IE entry in development log
Started GET "/semantic/country/5" for 127.0.0.1 at Wed Sep 07 12:06:00
+0200 2011 Processing by Semantic::SemanticController#country as HTML
Parameters: {"id"=>"5"} Country Load (1.0ms) SELECT countries.*
FROM countries WHERE countries.id = 5 LIMIT 1 Rendered
semantic/semantic/country.js.erb (1.0ms) Completed 200 OK in 1785ms
(Views: 54.0ms | ActiveRecord: 1.0ms)
Firefox call in development log
Started GET "/semantic/country/5" for 127.0.0.1 at Wed Sep 07 12:06:00
+0200 2011 Processing by Semantic::SemanticController#country as JS
Parameters: {"id"=>"5"} Country Load (1.0ms) SELECT countries.*
FROM countries WHERE countries.id = 5 LIMIT 1 Rendered
semantic/semantic/country.js.erb (1.0ms) Completed 200 OK in 1785ms
(Views: 54.0ms | ActiveRecord: 1.0ms)
The code used to generate the link is the following (in HAML):
link_to #vacancy.country.name, semantic_country_url(#vacancy.country.id), {:remote => true, :class => 'ajax'}
The problem seems to be how IE interprets the data-remote stuff in the HTML5. Is there a solution around this?
without switching to jquery, beause I cannot rewrite all the javascript in the application.
EDIT
Found out that the IE browser sends the request twice now,first time a JS, which works fine, but second time as HTML.
don't run firebug AND IEdevtools at the same time...They both respond to the feedback messages and start acting weird in this case.
Once I shut down Firebug IE worked fine.
I am using Clearance gem. It's "half" working.
I can do all basic actions (sign up, sign in, :authorize).
But, when I do a POST action to a controller, it just signs me out ...
Here what's in the log :
Started POST "/monkeys" for 127.0.0.1 at Fri Jun 03 06:22:00 -0400 2011
Processing by MonkeysController#create as HTML
Parameters: {"commit"=>"Save monkey", "authenticity_token"=>"[FILTERED]", "utf8"=>"\342\234\223", "monkey"=>{"name"=>"fghfgh", "description"=>"fghfgh"}}
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`remember_token` = 'c1f450a81fde65282e73ce41f69095b66d782e34' LIMIT 1
SQL (0.1ms) BEGIN
AREL (0.3ms) UPDATE `users` SET `remember_token` = 'b9c2cac3d446bee370e40619c6c8cd42c457bb13', `updated_at` = '2011-06-03 10:22:00' WHERE `users`.`id` = 4
SQL (1.1ms) COMMIT
Redirected to http://localhost:3000/sign_in
When that happens, I am actually signed in.. what might I have missed?
Thanks
It was actually because of my cookie domain, for some reason, localhost is not right. So i added a simple dns called "monkey.local" on my machine, and now I access the application with it and all works fine.
I also believe I can use 127.0.0.0 and it would work. I'll try it at home.
I tried out rails 3, and just started a new project. The following is all I typed.
rails new todo
cd todo
bundle install
rails generate scaffold Task done:boolean task:text created:date
rake db:migrate
rails server&
firefox 0.0.0:3000/tasks&
On page 0.0.0:3000/tasks/new, I filled in some values for the fields, and clicked the button to create a new task. It redirects to 0.0.0:3000/tasks with a blank page. When I manually reload the page, it shows up eight tasks even though there is supposed to be only one.
When I further click either show, edit, or destroy, it says, for e.g.: ActiveRecord::RecordNotFound in TasksController#show Couldn't find Task with ID=1.
When I reload to 0.0.0:3000/tasks, all eight tasks are still there.
What is wrong with this? Is rails corrupted on my computer?
Log
When I click 'create tasks', the terminal displays
Started GET "/tasks/new" for 127.0.0.1
at 2011-05-13 22:04:26 -0400
Processing by TasksController#new as
HTML Rendered tasks/_form.html.erb
(6.7ms) Rendered tasks/new.html.erb
within layouts/application (25.3ms)
Completed 200 OK in 35ms (Views:
27.9ms | ActiveRecord: 0.0ms)
folowed by something like this repeated eight times with x in tasks/x varying from 1 to 8:
Started POST "/tasks" for 127.0.0.1 at
2011-05-13 22:04:32 -0400 Processing
by TasksController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"QZHWWyE5KcZhLrzRhB4Fgnl9HGiQqNkn17O4CUfUUJU=",
"task"=>{"done"=>"0",
"task"=>"test\r\n",
"created(1i)"=>"2011",
"created(2i)"=>"5",
"created(3i)"=>"14"},
"commit"=>"Create Task"} AREL
(0.2ms) INSERT INTO "tasks" ("done",
"task", "created", "created_at",
"updated_at") VALUES ('f', 'test ',
'2011-05-14', '2011-05-14
02:04:32.065805', '2011-05-14
02:04:32.065805') Redirected to
http://0.0.0:3000/tasks/2 Completed
302 Found in 17ms [2011-05-13
22:04:32] ERROR URI::InvalidURIError:
the scheme http does not accept
registry part: 0.0.0:3000 (or bad
hostname?)
/usr/local/lib/ruby/1.9.1/uri/generic.rb:746:in
rescue in merge'
/usr/local/lib/ruby/1.9.1/uri/generic.rb:743:in
merge'
/usr/local/lib/ruby/1.9.1/webrick/httpresponse.rb:163:in
setup_header'
/usr/local/lib/ruby/1.9.1/webrick/httpresponse.rb:101:in
send_response'
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:86:in
run'
/usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in
block in start_thread'
You're trying to access your site using 0.0.0:3000 which is an invalid address (I'm actually surprised this even gives you access to the site at all).
Open 0.0.0.0:3000 in Firefox instead, and it will work perfectly!
(You can also use localhost:3000 or 127.0.0.1:3000)
Task is a reserved word in Rails. I guess thats the reason why rails is behaving in a starnge way.
For a list of other reserved words please refer to any of these links
http://cheat.errtheblog.com/s/rails_reserved_words/
http://www.yup.com/articles/2007/01/31/no-reservations-about-keywords-in-ruby-on-rails
http://oldwiki.rubyonrails.org/rails/pages/ReservedWords
My app was working fine with Rails 2.2 and Facebooker 1.0.13, but I keep getting a 406 error with Rails 2.3.
I checked the mime type, canvas/iframe setting in Facebook, and the requests work fine outside of Facebook (i.e. I get the full app as long as I'm not accessing it within the Facebook iframe). Has something changed recently in the Facebook API that would cause this error? Or is there anything in Facebooker that you've found might be fixed quickly?
Here is my Dev log for reference:
Processing PostsController#index (for xx.xxx.xx.xxx at 2009-03-06 03:24:44) [GET]
Parameters: {"fb_sig_app_id"=>"xxxxx",
"fb_sig_in_iframe"=>"1",
"fb_sig_locale"=>"en_US",
"fb_sig_in_new_facebook"=>"1",
"fb_sig"=>"xxxxx",
"fb_sig_added"=>"1",
"fb_sig_expires"=>"xxxxx",
"fb_sig_session_key"=>"xxxxx",
"fb_sig_ss"=>"xxxxx",
"fb_sig_api_key"=>"xxxxx",
"fb_sig_time"=>"1236327886.7997",
"fb_sig_profile_update_time"=>"1228275036",
"fb_sig_user"=>"11111"}
User Columns (6.0ms) SHOW FIELDS FROM users
User Load (1.0ms) SELECT * FROM users WHERE (users.login = 11111) LIMIT 1
SQL (0.0ms) BEGIN
SQL (0.0ms) COMMIT
Competition Load (0.0ms) SELECT * FROM posts
Completed in 135ms (View: 8, DB: 8) | 406 Not Acceptable
[http://xx.xx.xxx.xxx/?fb_sig_in_iframe=1&
fb_sig_locale=en_US&
fb_sig_in_new_facebook=1&
fb_sig_time=xxxxx.xxxxx&
fb_sig_added=1&
fb_sig_profile_update_time=1228275036&
fb_sig_expires=xxxxx&
fb_sig_user=xxxxx&
...]
If more details are needed, I'll be glad to give them...:-)
Found the answer in the Facebook Forums:
http://forum.developers.facebook.com/viewtopic.php?pid=93648#p93648
Sorry for implying that Facebooker wasn't working correctly...What you're doing is GREAT Michael (et al), keep up the great work!