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.
Related
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?
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
I want use angularjs in a rails project and I'm new to angularjs. for this, I create a staticpage controller with index action. I set this page for root page:
config/routes.rb
Restauranteur::Application.routes.draw do
root "staticpage#index"
end
now I download angular.js and add to asset pipeline. I remove turbolink and add below code to view/layouts/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>
Then, I create HomeCtrl.js.coffee:
#restauranteur.controller 'HomeCtrl', ['$scope', ($scope) ->
# Notice how this controller body is empty
]
Now, I set an angular route for show default page, For this I create main.js.coffee and create a templates directory in public folder.
main.js.coffee:
#restauranteur = angular.module('restauranteur', [])
#restauranteur.config(['$routeProvider', ($routeProvider) ->
$routeProvider.
otherwise({
templateUrl: '../templates/home.html',
controller: 'HomeCtrl'
})
])
I create home.html in public/templates folder.
I want when I run the server,I see home.html, but the server run staticpage/index, where is the problem? Why home.html isn't set as root page and I cannot preview this?
server log:
Started GET "/" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Processing by StaticpageController#index as HTML
Rendered staticpage/index.html.erb within layouts/application (0.0ms)
Completed 200 OK in 12ms (Views: 11.0ms | ActiveRecord: 0.0ms)
Started GET "/assets/staticpage.css?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/restaurants.css?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/angular.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/main.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/angular/controllers/HomeCtrl.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Note: I use this tutorial for do this, but I am not successful.
There are two different layers of views involved in this example:
the Rails views
the ng-view of AngularJS
I think that 1) is actually working because you see that the application renders staticpage/index, just like you specified in the Rails routes.
To get 2) to work, you need to make sure that you include the main.js in the application.js using the require_tree . instruction you see in the tutorial you used.
After this is done, the Angular application will pick up the routes. It will detect that no route matches and executes the otherwise section. In your Rails log, you will see that it tries to request the view templates/home.html. Once this succeeds, the loaded view will be rendered client-side within the <div ng-view> element.
In my code I have this :
def confirm
#pal = Pal.find(params[:palid])
#newuser = User.new(newuser_params)
#newuser.username = #pal.phone
if #newuser.save
redirect_to(:controller => 'access', :action => 'index')
else
flash[:error] = "Retry."
render template: 'pals/new_password_asign'
end
end
private
def newuser_params
params.require(:newuser).permit(:username, :password_digest, :password_stored)
end
and after submitting my sign up form, I get redirected and the error "Retry" which I've specified.
Knowing that I create users and save them via rails console perfectly fine.
And this has got me thinking what would possibly prevent this from being saved?
What issues might occur during the saving?
======================================================
Rails v4
Ruby v2.02
I am using Bcrypt-ruby for authentication.
======================================================
Update #1
=======================================================
After adding the suggested solution of #mandeep, I now do get the error explanation, and in this explanation I get
" Password can't be blank "
Despite the fact that I do write the password before submiting
Check my sign up form
<%= form_for(:newuser, :url => {:action => 'confirm', :palid => #pal.id}) do |f| %>
<% if #newuser.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#newuser.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #newuser.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<table summary="user form fields">
<tr>
<th><%= f.label(:username, "User Name") %></th>
<td><%= f.text_field :username, :value => #newuser.username, :class => "controls", :disabled => "true" %></td>
</tr>
<tr>
<th><%= f.label(:password, "password") %></th>
<td><%= f.password_field(:password) %></td>
</tr>
</table>
<div class="form-actions">
<%= f.submit nil, :class => 'btn btn-primary' %>
</div>
<% end %>
<% #newuser.password_stored = #newuser.password %>
</div>
</body>
==============================================
Update #2
Log and params after being request by #mandeep
Started GET "/pals" for 127.0.0.1 at 2014-07-03 16:15:44 +0000
ActiveRecord::SchemaMigration Load (0.1ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by palsController#index as HTML
pal Load (0.4ms) SELECT `pals`.* FROM `pals`
Rendered pals/index.html.erb within layouts/application (9.8ms)
Completed 200 OK in 280ms (Views: 260.9ms | ActiveRecord: 0.4ms)
Started GET "/pals" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Processing by palsController#index as HTML
pal Load (0.7ms) SELECT `pals`.* FROM `pals`
Rendered pals/index.html.erb within layouts/application (6.3ms)
Completed 200 OK in 103ms (Views: 101.4ms | ActiveRecord: 0.7ms)
Started GET "/assets/access.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/pals.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/access.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/pals.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/pals/new" for 127.0.0.1 at 2014-07-03 16:16:11 +0000
Processing by PalsController#new as HTML
Rendered pals/_form.html.erb (24.7ms)
Rendered pals/new.html.erb within layouts/application (43.6ms)
Completed 200 OK in 106ms (Views: 101.2ms | ActiveRecord: 1.6ms)
Started POST "/pals" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Processing by PalsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8X6LD0g6E1HybdAF/FOlM09iuQLWExBY8dY5CqSDZsM=", "pal"=>{"owner"=>"John", "title"=>"", "phone"=>"22", "price"=>"", "logtype"=>"", "description"=>"", "address"=>"", "latitude"=>"", "longitude"=>""}, "commit"=>"Create pal"}
(0.3ms) BEGIN
SQL (0.3ms) INSERT INTO `pals` (`address`, `created_at`, `description`, `logtype`, `owner`, `phone`, `title`, `updated_at`) VALUES ('', '2014-07-03 16:16:19', '', '', 'John', '22', '', '2014-07-03 16:16:19')
(56.6ms) COMMIT
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`username` = '22'
Redirected to http://localhost:3000/pals/confirm?palid=5
Completed 302 Found in 77ms (ActiveRecord: 58.1ms)
Started GET "/pals/confirm?palid=5" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Processing by PalsController#confirm as HTML
Parameters: {"palid"=>"5"}
pal Load (0.6ms) SELECT `pals`.* FROM `pals` WHERE `pals`.`id` = 5 LIMIT 1
Rendered pals/confirm.html.erb within layouts/application (6.4ms)
Completed 200 OK in 63ms (Views: 52.4ms | ActiveRecord: 0.8ms)
Started GET "/assets/access.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/pals.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/access.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/pals.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started POST "/pals/confirm?palid=5" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Processing by PalsController#confirm as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8X6LD0g6E1HybdAF/FOlM09iuQLWExBY8dY5CqSDZsM=", "newuser"=>{"password"=>"[FILTERED]"}, "commit"=>"Save Newuser", "palid"=>"5"}
pal Load (0.2ms) SELECT `pals`.* FROM `pals` WHERE `pals`.`id` = 5 LIMIT 1
(0.6ms) BEGIN
(0.1ms) COMMIT
(0.1ms) BEGIN
(0.1ms) ROLLBACK
Rendered pals/confirm.html.erb within layouts/application (1.8ms)
Completed 200 OK in 60ms (Views: 50.6ms | ActiveRecord: 1.1ms)
Started GET "/assets/access.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/pals.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/pals.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/access.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
If you look at your code
def confirm
pal = Pal.find(params[:palid]) # you have find your pal and store it in "pal"
#newuser = User.new(newuser_params)
#newuser.username = #pal.phone # you are using instance variable "#pal" which is not defined
# your other logic
end
Instead you should have your code like:
def confirm
#pal = Pal.find(params[:palid])
#newuser = User.new(newuser_params)
#newuser.username = #pal.phone
# your other logic
end
Also in your form you should put this code
<% if #newuser.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#newuser.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #newuser.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
This will display if there are any validation errors in your form. For details refer to here
Update:
If you look at the parameters which are being passed from your form, notice this
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8X6LD0g6E1HybdAF/FOlM09iuQLWExBY8dY5CqSDZsM=", "newuser"=>{"password"=>"[FILTERED]"}, "commit"=>"Save Newuser", "palid"=>"5"}
There are couple of things wrong in your form:
a. Either you didn't enter your username in form or you haven't made your form properly because in params it's only showing password field "newuser"=>{"password"=>"[FILTERED]"}
b. You haven't permit your password field instead of permitting password you have permitted :password_digest, :password_stored. Your newuser_params should look like this:
def newuser_params
params.require(:newuser).permit(:username, :password)
end
c. what is "palid"=>"5" doing in your params? Is it a field in your form or what because it's not associated to newuser params
Check the validation errors in #newuser, namely #newuser.errors. There are methods that skip validations. Maybe you are using them in the console.
When these partials are loaded in the browser I am unable to navigate away from the page via the browser back button. The page stays the same but the url changes.
What could be causing this?
match '/signup', to: 'users#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'get'
# /users/new
def new
#user = User.new
render partial: "new", layout: false
end
# /sessions/new
def new
render partial: "new", layout: false
end
Here's my stack. This is from just clicking the signin link once.
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Processing by SessionsController#new as */*
Processing by SessionsController#new as */*
Rendered sessions/_new.html.erb (0.8ms)
Rendered sessions/_new.html.erb (0.8ms)
Completed 200 OK in 4ms (Views: 3.3ms | ActiveRecord: 0.0ms)
Completed 200 OK in 4ms (Views: 3.3ms | ActiveRecord: 0.0ms)
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Processing by SessionsController#new as HTML
Processing by SessionsController#new as HTML
Rendered sessions/_new.html.erb (0.8ms)
Rendered sessions/_new.html.erb (0.8ms)
Completed 200 OK in 3ms (Views: 1.9ms | ActiveRecord: 0.0ms)
Completed 200 OK in 3ms (Views: 1.9ms | ActiveRecord: 0.0ms)
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Processing by SessionsController#new as HTML
Processing by SessionsController#new as HTML
Rendered sessions/_new.html.erb (0.8ms)
Rendered sessions/_new.html.erb (0.8ms)
Completed 200 OK in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms)
Completed 200 OK in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms)
Do you have a before filter redirecting public access to sessions#new? Have you defined /signin as a route?
I might be wrong, but as I wrote in the comment while ago I had a customer that used Turbolinks on Rails 3.2.12 and a group of customized JS libraries. The Turbolinks was causing a lot of issues such as double submitting and one of them was a similar thing to what you have mentioned. I had 3 choices:
1- Take out Turbolinks (my temp solution, until I showed the team TL was causing it)
2- Change the JS lib dependencies
3- Update the Rails App to 4.x latest. (I did this finally, it wasn't too bad)
In case if I was wrong and your case and setup was not similar to mine, here is a good thread on Github that some guy tries to solve it and still seems to be open.
https://github.com/rails/turbolinks/issues/256
Check your parameters :
Processing SESSION::SESSION#new (for 127.0.0.1 at 2014-04-04 13:50:03) [POST]
Parameters: {"authenticity_token"=>"XXXXX=", "param1"=>"1"}
Well in your log you will see what params you are sending if it is not sending what you want create params according to your columns or what you want to keep.
If you want create a back button you could try this:
link_to_function "Back", "history.back()"
Check your action form maybe you are sending other url
<% form_tag :controller=>"sessions",:action=>"new" do %>
<% #user.each do |user| %>
<%= user.name %>
<%= user.lastname %>
<% end %>
<% end %>