Trying to create VueJS Axios request to API (rails backend) and get duplication of parameters in the request.
My vue request to server:
onlogin () {
axios.post('http://localhost:3000/auth/sign_in', {
email: this.email,
password: this.password,
})
In the terminal see:
Started OPTIONS "/auth/sign_in" for ::1 at 2019-09-10 23:03:02 +0300
Started POST "/auth/sign_in" for ::1 at 2019-09-10 23:03:02 +0300
Processing by Users::SessionsController#create as HTML
Parameters: {"email"=>"mail#mail.com", "password"=>"[FILTERED]", "session"=>{"email"=>"mail#mail.com", "password"=>"[FILTERED]"}}
Unpermitted parameter: :session
Unpermitted parameter: :session
This request from Postman is OK:
Started POST "/auth/sign_in?email=mail#mail.com&password=[FILTERED]" for ::1 at 2019-09-10 23:05:09 +0300
Processing by Users::SessionsController#create as */*
Parameters: {"email"=>"mail#mail.com", "password"=>"[FILTERED]"}
Any idea why the :session parameters is added to request?
Related
I have 2 Rails apps, App1 and App2.
App1 contains links to controller actions in App2 which in turn returns files (downloads), e.g.:
<%= link_to "Download Video", "http://app2/downloads/download_video", :target => "_bkank" %>
with "downloads" being and controller within App2 and "download_video" being an action of the "downloads" controller:
def download_video
send_file '/path/to/video/video.mp4', type: "video/mp4", :disposition => "inline"
end
Upon clicking the link, a new window (tab) is opened and the video is played in the window - this is a desired behavior .... my problem is, when looking t the logs, I see that the same GET request is sent 3 times - the first as HTML and then as / twice:
Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:45 +0200
Processing by DownloadsController#download_video as HTML
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:46 +0200
Processing by DownloadsController#download_video as */*
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:46 +0200
Processing by DownloadsController#download_video as */*
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 0ms
Could anyone let me know why this is happening and how I can prevent it?
Thanks,
Jon.
#praga2050,
can you please post entire controller code ...
yes:
class DownloadsController < ApplicationController
def download_video
send_file '/var/www/videos/video.mp4', type: "video/mp4", :disposition => "inline"
end
end
#praga2050,
... try putting Rails.logger.debug with time stamp and see
yes:
Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as HTML
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as */*
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as */*
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 1ms
warden.authenticate!(auth_options)
working fine for these params:
{"utf8"=>"✓",
"authenticity_token"=>"5BMAUoZLUEgPZBVOAcQ8lFD4+pumP9kEvvXyelbnjeO36AZJQt2oRlraicQ6quvh/dccS0ELUkxjACgFcWFYAg==",
"user"=>{"email"=>"vijay#xyz.com", "password"=>"xyz",
"phone"=>"9443429932"}, "action"=>"create", "controller"=>"sessions",
"format"=>"json", "session"=>{"user"=>{"email"=>"vijay#xyz.com",
"password"=>"xyz", "phone"=>"9443429932"}}}
but failing for these:
{"utf8"=>"✓",
"authenticity_token"=>"/ly2phwfsD3HEVkHK39ajYQGv6R4uj2z3B+3eiZEU0qtp7C92IlIM5KvxY0QEY34KSlZdJ+OtvsB6m0FAcKGqw==",
"user"=>{"phone"=>"9443429932", "password"=>"xyz",
"email"=>"vijay#xyz.com"}, "action"=>"create",
"controller"=>"sessions", "format"=>"json",
"session"=>{"user"=>{"phone"=>"9443429932", "password"=>"xyz",
"email"=>"vijay#xyz.com"}}}
The data is the same in both cases except for the order.
Stuck with this for long.
here is the log:
Started POST "/users/sign_in.json" for 127.0.0.1 at 2017-04-10
10:53:07 +0530 Processing by SessionsController#create as JSON
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"XVMbYLTgv4eFbv9pX5lJD3U6DHF17o18rVIjqQLo4skOqB17cHZHidDQY+Nk95562BXqoZLaBjRwp/nWJW43KA==",
"user"=>{"phone"=>"9443429932", "password"=>"[FILTERED]"},
"session"=>{"user"=>{"phone"=>"9443429932",
"password"=>"[FILTERED]"}}} User Load (0.3ms) SELECT users.* FROM
users WHERE users.id = 12422916 AND (invitation_token is null)
LIMIT 1 Completed 401 Unauthorized in 15ms
Found the issue.
warden is reading the params from request.params
I have edited the params, but it was not reflecting in request.params.
request.params[:user].merge!(params[:user])
This fixed the issue.
When I click 'log out' I can see that Rails processess the request, but I'm still logged in.
Any clue why this happens? Both locally and on Heroku.
Started DELETE "/users/sign_out" for IP at 2014-11-18 08:32:46 +0000
Processing by Devise::SessionsController#destroy as HTML
Parameters: {"authenticity_token"=>"TOKEN"}
Redirected to http://example.com/
Completed 302 Found in 14ms (ActiveRecord: 4.4ms)
Started GET "/" for 84.215.64.133 at 2014-11-18 08:32:47 +0000
Processing by StaticPagesController#blog as HTML
Rendered static_pages/blog.html.slim within layouts/application (0.7ms)
Completed 200 OK in 6ms (Views: 2.9ms | ActiveRecord: 1.6ms)
routes.rb
devise_for :users
From the log when editing a user:
Started PUT "/users" for 84.215.64.133 at 2014-11-18 14:40:30 +0000
Processing by Devise::RegistrationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"QR/p3BAG+ocmacss5xDjuFDfhFSA+iv6VRK37uA9HcQ=", "user"=>{"mobile"=>"93441707", "email"=>"sss#
strosin.info", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Lagre"}
2014-11-18T14:40:31.095730+00:00 app[web.2]: App 131 stdout: Redirected to http://
The problem disapeared when I cleared the browser cache. (Using Chrome beta).
I want use angularjs in rails application and I'm new to angularjs. For this, I add angularjs file to project and created the below scripts and html:
HomeCtrl.js.coffee
#restauranteur.controller 'HomeCtrl', ['$scope', ($scope) ->
# Notice how this controller body is empty
]
RestaurantIndexCtrl.js.coffee:
#restauranteur.controller 'RestaurantIndexCtrl', ['$scope', '$location', '$http', ($scope, $location, $http) ->
$scope.restaurants = []
$http.get('./restaurants.json').success((data) ->
$scope.restaurants = data
)
]
main.js.coffee:
#restauranteur = angular.module('restauranteur', [])
#restauranteur.config(['$routeProvider', ($routeProvider) ->
$routeProvider.when('/restaurants', {
templateUrl: '../templates/restaurants/index.html',
controller: 'RestaurantIndexCtrl'
})
.otherwise({
templateUrl: '../templates/home.html',
controller: 'HomeCtrl'
})
])
I add below code to application.js:
//= require angular
//= require angular-mocks
//= require angular-route
//= require main
//= require HomeCtrl
//= require RestaurantIndexCtrl
and in application.html.erb:
<!DOCTYPE html>
<html ng-app="restauranteur">
<head>
<title>Restauranteur</title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div ng-view>
<%= yield %>
</div>
</body>
</html>
and I created templates/home.html and templates/restaurants/index.html directories in public folder.
now I want render templates/home.html on localhost:3000 and render templates/restaurants/index.html on localhost:3000/restaurants. But I'm not successful and rails is rendered default page. I check my server log, every js and angularjs file are renderd, but when I go to localhost:3000/restaurants url, rails rendered default page of restaurants. (restaurants is a model that generated by sccafold.) How can I render angularjs html instead of rails html? Any idea?
server log:
Started GET "/restaurants" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Processing by RestaurantsController#index as HTML
Restaurant Load (0.0ms) SELECT "restaurants".* FROM "restaurants"
Rendered restaurants/index.html.erb within layouts/application (1.0ms)
Completed 200 OK in 12ms (Views: 11.0ms | ActiveRecord: 0.0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/restaurants.css?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/staticpage.css?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/angular.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/main.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/angular/controllers/HomeCtrl.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/angular/controllers/RestaurantIndexCtrl.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Note: For do this, I use this tutorial.
At first, if you want use routing, you must add this line in your app initialization:
#restauranteur = angular.module('restauranteur', ['ngRoute'])
And if you want url such as localhost:3000/restaurants, you must use html5-routing.
#restauranteur.config(['$locationProvider', '$urlRouterProvider',
function($locationProvider, $urlRouterProvider) {
$locationProvider.html5Mode(true).hashPrefix('!');
...
...
}
]);
Otherwise, just try localhost:3000/#/restaurants.
i am trying to register from an iOS App to a rails backend.
rake routes
tells me:
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
So on the iOS Side i am trying this:
NSDictionary *parameters = #{
#"email": username,
#"password": password,
#"password_confirmation": passwordConfirmation
};
[[ADCAPIClient sharedClient] postPath:#"users"
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject)
I am getting an Unknown Format exception:
Started POST "/users" for 192.168.178.21 at 2013-11-02 18:53:08 +0100
Processing by Devise::RegistrationsController#create as JSON
Parameters:
{"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"abc#def.de",
"registration"=>{"password"=>"[FILTERED]", "password_confirmation"=>
"[FILTERED]", "email"=>"abc#def.de"}}
Can't verify CSRF token authenticity
(0.1ms) BEGIN
(0.1ms) ROLLBACK
Completed 406 Not Acceptable in 6ms
ActionController::UnknownFormat (ActionController::UnknownFormat):
If i connect through the devise generated view in the browser it works and the request it sends looks like this:
Started POST "/users" for 127.0.0.1 at 2013-11-03 10:58:54 +0100
Processing by Devise::RegistrationsController#create as HTML
Parameters:
{"utf8"=>"✓", "authenticity_token"=>"xxxx", "user"=>{"email"=>"abc#def.de", "password"=>
[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.2ms) BEGIN
...
I am doing the client backend communication for the first time, so i cannot figure out how the right request would look like?! I have searched stackoverflow, but the answers are pretty unsatisfying.
Can somebody help or provide me a link to a good explanation or tutorial?
Thanks in advance!