This is from users_controller.rb
class UsersController < ApplicationController
before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update]
before_action :admin_user, only: [:destroy]
. . .
def destroy
User.find(params[:id]).destroy
flash[:success] = "User deleted"
redirect_to users_url
end
I still don't know where the error is. Can somebody help me, please? Thanks.
I have attached the log from the console. I hope this helps.
Log
AbstractController::ActionNotFound (The action 'destroy' could not be found for UsersController):
actionpack (5.0.0.1) lib/abstract_controller/base.rb:121:in `process'
actionview (5.0.0.1) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.0.1) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.0.1) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call'
rack (2.0.1) lib/rack/etag.rb:25:in `call'
rack (2.0.1) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.1) lib/rack/head.rb:12:in `call'
rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.0.0.1) lib/active_record/migration.rb:552:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
web-console (3.1.1) lib/web_console/middleware.rb:131:in `call_app'
web-console (3.1.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.1.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.1.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.0.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `tagged'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
Routes.rb
Rails.application.routes.draw do
root 'static_pages#home'
get '/help', to: 'static_pages#help', as: :help
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
get '/signup', to: 'users#new'
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
delete '/logout', to: 'sessions#destroy'
resources :users
end
Index.html.erb
<% provide(:title, 'All users') %>
<h1>All users</h1>
<%-#= will_paginate #users -%>
<% #users = User.all %>
<ul class="users">
<% #users.each do |user| %>
<%= render #users %>
<% end %>
</ul>
<%-#= will_paginate #users -%>
I have added the log, as requested.
Related
I am using spring mvc, thymeleaf and basic html to register a user, after registering the user is prompted to enter his position with a form, how can i pass the registered users id and the selected "position" to the spring controller.
Here is my html:
Logged in
<h4>Player: <h4 th:text="${username}" /> </h4>
<h4>ID:<h4 th:text="${id}" /> </h4>
<a style="color:blue" th:href="#{/home}">HomeScreen!</a>
</center>
<center>
<h4>Update Position</h4>
<form action="#" th:action="#{/updatePlayer}" th:object="${player}" method="post">
<table>
<tr>
<td>Preferred Position:</td>
<td><select name="Position" th:field="*{position}" >
<option value="TightHead">TightHead (1)</option>
<option value="Hooker">Hooker (2)</option>
<option value="LooseHead">LooseHead (3)</option>
<option value="SecondRow">Second Row (4/5)</option>
<option value="BlindSideFlanker">Blindside Flanker(6)</option>
<option value="OpenSideFlanker">Openside Flanker(7)</option>
<option value="Eight">Eight(8)</option>
<option value="ScrumHalf">ScrumHalf(9)</option>
<option value="OutHalf">OutHalf(10)</option>
<option value="LeftWing">Left Wing(11)</option>
<option value="InsideCentre">Inside Centre (12)</option>
<option value="OutsideCentre">Outside Centre (13)</option>
<option value="RightWing">Right Wing (14)</option>
<option value="FullBack">Fullback (15)</option>
</select></td>
</tr>
<tr>
<td></td><td><button type="submit">Submit</button></td>
</tr>
</table>
</form>
</td>
<br />
<a style="color:blue" th:href="#{/home}">HomeScreen!</a>
</center>
As you can see from this I am able to display the newly registered users id by passing it through the controller.
In the position form I am passing th:object = player when I should be passing the variable "position" but unsure how.
Here is my controller:
#RequestMapping(value = "/updatePlayer", method = RequestMethod.POST)
public String updatePlayer(#RequestParam("id") Long id, #RequestParam("position") String position) {
//
UserLogin updateUser = userRepository.findOne(id);
updateUser.setPosition(position);
userRepository.save(updateUser);
//need to figure out how to pass variable from update form to here and set the "user"s position to the selected value
return "welcome";
}
I am requesting the variables: id, position from the html page using #ParamRequest but am getting the following error:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'position' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.thymeleaf.spring4.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:401) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.spring4.util.FieldUtils.getBindStatus(FieldUtils.java:328) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.spring4.util.FieldUtils.getBindStatus(FieldUtils.java:294) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.spring4.processor.attr.AbstractSpringFieldAttrProcessor.processAttribute(AbstractSpringFieldAttrProcessor.java:98) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.processor.attr.AbstractAttrProcessor.doProcess(AbstractAttrProcessor.java:87) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.applyNextProcessor(Node.java:1017) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:972) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Document.process(Document.java:93) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1155) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:190) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:124) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:347) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:263) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.23.jar:8.5.23]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_60]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.23.jar:8.5.23]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_60]
Its because th:field=*{some user field}" is for binding your input with a property in the form-backing bean, like if you were injecting #ModelAttribute User user in controller.
However, your controller is trying to inject Long id and String position, so in your form you need to have two th:name with user id and selected position accordingly.
The first problem comes from you controlor.
As you want to handle the form from a POST request, the form content will not be send by url.
The best wait could be to create a simple object you call something like playerPositionForm, initialize,and add it to the model in your GET controllor.
public String display(Model model) {
final PlayerPositionFormregleForm playerPositionForm = new playerPositionForm();
model.addAttribute("playerPositionForm ", playerPositionForm ); return "view";
In your HTML you have to bind it to the form. Just replace
th:object="${player}"
by
th:object="${playerPositionForm }"
And finally in your POST method
#RequestMapping(value = "/updatePlayer", method = RequestMethod.POST)
public String updatePlayer(#RequestParam("id") Long id, #ModelAttribute("playerPositionForm ") PlayerPositionFormregleForm,Model model playerPositionForm ) {
Getting following authentication exception while authenticating against LDAP using spring 4.0 security:
Following is full stack trace of this issue :
org.springframework.ldap.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903A8, comment: AcceptSecurityContext error, data 52e, v1db1
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:191) at
org.springframework.ldap.core.support.AbstractContextSource.createContext(AbstractContextSource.java:355)
at org.springframework.ldap.core.support.AbstractContextSource.doGetContext(AbstractContextSource.java:139)
at org.springframework.ldap.core.support.AbstractContextSource.getContext(AbstractContextSource.java:130)
at com.globalpay.bvlogin.security.ldap.service.impl.BvLoginCustomBindAuthenticator.bindWithDn(BvLoginCustomBindAuthenticator.java:95)
at com.globalpay.bvlogin.security.ldap.service.impl.BvLoginCustomBindAuthenticator.bindWithDn(BvLoginCustomBindAuthenticator.java:81)
at com.globalpay.bvlogin.security.ldap.service.impl.BvLoginCustomBindAuthenticator.authenticate(BvLoginCustomBindAuthenticator.java:61)
at org.springframework.security.ldap.authentication.LdapAuthenticationProvider.doAuthentication(LdapAuthenticationProvider.java:187)
at org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider.authenticate(AbstractLdapAuthenticationProvider.java:85)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:174)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:199)
at org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:94)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:124)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:134)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903A8, comment: AcceptSecurityContext error, data 52e, v1db1
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3136)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3082)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2883)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2797)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:319)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:192)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:210)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:153)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:83)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.init(InitialContext.java:244)
at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:154)
at org.springframework.ldap.core.support.LdapContextSource.getDirContextInstance(LdapContextSource.java:42)
at org.springframework.ldap.core.support.AbstractContextSource.createContext(AbstractContextSource.java:343)
... 45 more
------------------------------------------------------------------------------
Following is the configuration in spring-sec-config.xml file:
<security:http use-expressions="true">
<security:intercept-url pattern="/login" access="isAnonymous()" />
<security:intercept-url pattern="/**" access="permitAll()" />
<security:intercept-url pattern="/welcome" access="isAuthenticated()" />
<security:form-login login-page="/"
authentication-failure-url="/?error" login-processing-url="/performLogin"
username-parameter="username" password-parameter="password" />
<!-- <security:logout logout-success-url="/login" /> -->
<security:session-management
session-fixation-protection="migrateSession" invalid-session-url="/performLogout">
<security:concurrency-control
max-sessions="1" error-if-maximum-exceeded="false" />
</security:session-management>
<security:csrf />
<security:headers>
<security:cache-control />
<security:content-type-options />
<security:xss-protection />
<security:frame-options />
<security:hsts />
</security:headers>
</security:http>
<security:authentication-manager alias="ldapAuthManager">
<security:authentication-provider
ref="ldapAuthProvider" />
</security:authentication-manager>
<bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg
value="ldaps://company.team.san.com:636/DC=team,DC=san,DC=com" />
<property name="userDn" value="cn=service_crs,OU=ServiceAccounts,OU=Administration,DC=team,DC=san,DC=com" />
<property name="password" value="${ldap.adminUserPassword}" />
</bean>
<bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
<constructor-arg ref="bindAuthenticator" />
<constructor-arg>
<bean
class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
<constructor-arg ref="contextSource" />
<constructor-arg value="ou=ExternalUsers" />
<property name="groupRoleAttribute" value="ou" />
</bean>
</constructor-arg>
</bean>
<bean
class="org.springframework.security.ldap.authentication.BindAuthenticator"
id="bindAuthenticator">
<constructor-arg ref="contextSource" />
<!-- <property name="userSearch" ref="userSearch" /> -->
<property name="userDnPatterns">
<list>
<value>uid={0},OU=ExternalUsers</value>
<!-- <value>uid={0},ou=Administration</value> -->
</list>
</property>
</bean>
<!-- <security:ldap-server ldif="classpath:users.ldif" root="dc=san,dc=org"/> -->
</beans>
Any help to resolve this issue will be appreciated. :)
Thanks in advance.
LDAP: error code 49
means 'invalid credentials', sometimes this error code is also returned (for security reasons) when the entry/account is locked
When I try to install jruby modules, I get this mess, always starting with that java.lang.ArrayIndexOutOfBoundsException bit:
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
System.java:-2:in `arraycopy': java.lang.ArrayIndexOutOfBoundsException
from DefaultResolver.java:111:in `makeTime'
from DefaultResolver.java:277:in `create'
from DefaultResolver.java:317:in `handleScalar'
from DefaultResolver.java:435:in `orgHandler'
from DefaultResolver.java:455:in `node_import'
from org/yecht/ruby/DefaultResolver$s_method_1_0$RUBYINVOKER$node_import.gen:65535:in `call'
from CachingCallSite.java:146:in `call'
from RubyLoadHandler.java:39:in `handle'
from Parser.java:300:in `addNode'
from DefaultYAMLParser.java:676:in `yyparse'
from Parser.java:290:in `yechtparse'
from Parser.java:284:in `parse'
from YParser.java:152:in `load'
from org/yecht/ruby/YParser$s_method_0_1$RUBYINVOKER$load.gen:65535:in `call'
from JavaMethod.java:630:in `call'
from DynamicMethod.java:186:in `call'
from CachingCallSite.java:309:in `cacheAndCall'
from CachingCallSite.java:148:in `call'
from CallOneArgNode.java:57:in `interpret'
from LocalAsgnNode.java:123:in `interpret'
from NewlineNode.java:104:in `interpret'
from InterpretedMethod.java:180:in `call'
from DefaultMethod.java:174:in `call'
from CachingCallSite.java:309:in `cacheAndCall'
from CachingCallSite.java:148:in `call'
from CallOneArgNode.java:57:in `interpret'
from LocalAsgnNode.java:123:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:180:in `call'
from DefaultMethod.java:174:in `call'
from CachingCallSite.java:309:in `cacheAndCall'
from CachingCallSite.java:148:in `call'
from CallOneArgNode.java:57:in `interpret'
from NewlineNode.java:104:in `interpret'
from RescueNode.java:199:in `executeBody'
from RescueNode.java:118:in `interpretWithJavaExceptions'
from RescueNode.java:110:in `interpret'
from InterpretedMethod.java:180:in `call'
from DefaultMethod.java:174:in `call'
from CachingCallSite.java:309:in `cacheAndCall'
from CachingCallSite.java:148:in `call'
from FCallOneArgNode.java:36:in `interpret'
from InstAsgnNode.java:95:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from EnsureNode.java:96:in `interpret'
from BeginNode.java:83:in `interpret'
from NewlineNode.java:104:in `interpret'
from WhenOneArgNode.java:36:in `whenSlowTest'
from WhenOneArgNode.java:46:in `when'
from CaseNode.java:133:in `interpret'
from NewlineNode.java:104:in `interpret'
from InterpretedBlock.java:373:in `evalBlockBody'
from InterpretedBlock.java:346:in `yield'
from InterpretedBlock.java:303:in `yield'
from Block.java:194:in `yield'
from YieldNode.java:112:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedBlock.java:373:in `evalBlockBody'
from InterpretedBlock.java:346:in `yield'
from InterpretedBlock.java:303:in `yield'
from Block.java:194:in `yield'
from RubyKernel.java:1251:in `loop_1_9'
from org/jruby/RubyKernel$s_method_0_0$RUBYFRAMEDINVOKER$loop_1_9.gen:65535:in `call'
from CachingCallSite.java:299:in `cacheAndCall'
from CachingCallSite.java:117:in `callBlock'
from CachingCallSite.java:132:in `callIter'
from FCallNoArgBlockNode.java:32:in `interpret'
from NewlineNode.java:104:in `interpret'
from InterpretedMethod.java:160:in `call'
from DefaultMethod.java:166:in `call'
from CachingCallSite.java:299:in `cacheAndCall'
from CachingCallSite.java:117:in `callBlock'
from CachingCallSite.java:122:in `call'
from CallNoArgBlockNode.java:64:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:242:in `call'
from DefaultMethod.java:198:in `call'
from CachingCallSite.java:339:in `cacheAndCall'
from CachingCallSite.java:197:in `callBlock'
from CachingCallSite.java:202:in `call'
from RubyClass.java:819:in `call'
from DynamicMethod.java:194:in `call'
from WrapperMethod.java:62:in `call'
from CachingCallSite.java:329:in `cacheAndCall'
from CachingCallSite.java:188:in `call'
from FCallTwoArgNode.java:38:in `interpret'
from LocalAsgnNode.java:123:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from EnsureNode.java:96:in `interpret'
from InterpretedMethod.java:242:in `call'
from DefaultMethod.java:198:in `call'
from CachingCallSite.java:339:in `cacheAndCall'
from CachingCallSite.java:197:in `callBlock'
from CachingCallSite.java:202:in `call'
from CallTwoArgBlockPassNode.java:62:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:283:in `call'
from DefaultMethod.java:214:in `call'
from CachingCallSite.java:359:in `cacheAndCall'
from CachingCallSite.java:237:in `callBlock'
from CachingCallSite.java:252:in `callIter'
from CallThreeArgBlockNode.java:64:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:262:in `call'
from DefaultMethod.java:206:in `call'
from CachingCallSite.java:349:in `cacheAndCall'
from CachingCallSite.java:228:in `call'
from FCallThreeArgNode.java:40:in `interpret'
from NewlineNode.java:104:in `interpret'
from InterpretedBlock.java:373:in `evalBlockBody'
from InterpretedBlock.java:346:in `yield'
from InterpretedBlock.java:303:in `yield'
from Block.java:194:in `yield'
from RubyIO.java:1106:in `open'
from RubyKernel.java:283:in `open'
from org/jruby/RubyKernel$s_method_0_2$RUBYFRAMEDINVOKER$open.gen:65535:in `call'
from DynamicMethod.java:198:in `call'
from CachingCallSite.java:339:in `cacheAndCall'
from CachingCallSite.java:197:in `callBlock'
from CachingCallSite.java:212:in `callIter'
from FCallTwoArgBlockNode.java:34:in `interpret'
from NewlineNode.java:104:in `interpret'
from IfNode.java:119:in `interpret'
from IfNode.java:119:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:221:in `call'
from DefaultMethod.java:190:in `call'
from CachingCallSite.java:329:in `cacheAndCall'
from CachingCallSite.java:188:in `call'
from CallTwoArgNode.java:59:in `interpret'
from InstAsgnNode.java:95:in `interpret'
from NewlineNode.java:104:in `interpret'
from RescueNode.java:199:in `executeBody'
from RescueNode.java:118:in `interpretWithJavaExceptions'
from RescueNode.java:110:in `interpret'
from BeginNode.java:83:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:242:in `call'
from DefaultMethod.java:198:in `call'
from CachingCallSite.java:339:in `cacheAndCall'
from CachingCallSite.java:197:in `callBlock'
from CachingCallSite.java:202:in `call'
from RubyClass.java:819:in `call'
from DynamicMethod.java:194:in `call'
from CachingCallSite.java:329:in `cacheAndCall'
from CachingCallSite.java:188:in `call'
from CallTwoArgNode.java:59:in `interpret'
from DAsgnNode.java:110:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedBlock.java:373:in `evalBlockBody'
from InterpretedBlock.java:346:in `yield'
from InterpretedBlock.java:303:in `yield'
from Block.java:194:in `yield'
from RubyArray.java:1630:in `eachCommon'
from RubyArray.java:1637:in `each'
from org/jruby/RubyArray$i_method_0_0$RUBYFRAMEDINVOKER$each.gen:65535:in `call'
from CachingCallSite.java:299:in `cacheAndCall'
from CachingCallSite.java:117:in `callBlock'
from CachingCallSite.java:122:in `call'
from CallNoArgBlockNode.java:64:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:221:in `call'
from DefaultMethod.java:190:in `call'
from CachingCallSite.java:329:in `cacheAndCall'
from CachingCallSite.java:188:in `call'
from CallTwoArgNode.java:59:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from RescueNode.java:199:in `executeBody'
from RescueNode.java:118:in `interpretWithJavaExceptions'
from RescueNode.java:110:in `interpret'
from BeginNode.java:83:in `interpret'
from NewlineNode.java:104:in `interpret'
from InterpretedBlock.java:373:in `evalBlockBody'
from InterpretedBlock.java:346:in `yield'
from InterpretedBlock.java:303:in `yield'
from Block.java:194:in `yield'
from RubyArray.java:1630:in `eachCommon'
from RubyArray.java:1637:in `each'
from org/jruby/RubyArray$i_method_0_0$RUBYFRAMEDINVOKER$each.gen:65535:in `call'
from CachingCallSite.java:299:in `cacheAndCall'
from CachingCallSite.java:117:in `callBlock'
from CachingCallSite.java:122:in `call'
from CallNoArgBlockNode.java:64:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:139:in `call'
from DefaultMethod.java:158:in `call'
from CachingCallSite.java:289:in `cacheAndCall'
from CachingCallSite.java:108:in `call'
from VCallNode.java:85:in `interpret'
from NewlineNode.java:104:in `interpret'
from IfNode.java:119:in `interpret'
from IfNode.java:119:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:180:in `call'
from DefaultMethod.java:174:in `call'
from CachingCallSite.java:309:in `cacheAndCall'
from CachingCallSite.java:148:in `call'
from CallSpecialArgNode.java:67:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from CaseNode.java:138:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:180:in `call'
from DefaultMethod.java:174:in `call'
from CachingCallSite.java:309:in `cacheAndCall'
from CachingCallSite.java:148:in `call'
from FCallOneArgNode.java:36:in `interpret'
from NewlineNode.java:104:in `interpret'
from RescueNode.java:199:in `executeBody'
from RescueNode.java:118:in `interpretWithJavaExceptions'
from RescueNode.java:110:in `interpret'
from InterpretedMethod.java:180:in `call'
from DefaultMethod.java:174:in `call'
from CachingCallSite.java:309:in `cacheAndCall'
from CachingCallSite.java:148:in `call'
from CallOneArgNode.java:57:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from InterpretedMethod.java:180:in `call'
from DefaultMethod.java:174:in `call'
from CachingCallSite.java:309:in `cacheAndCall'
from CachingCallSite.java:148:in `call'
from gem:24:in `rescue_1$RUBY$__rescue___0'
from gem:23:in `__file__'
from gem:-1:in `load'
from Ruby.java:692:in `runScript'
from Ruby.java:575:in `runNormally'
from Ruby.java:418:in `runFromMain'
from Main.java:286:in `run'
from Main.java:128:in `run'
from Main.java:97:in `main'
Per Unable to install rails with jRuby I tried jruby -S gem install jruby-openssl but I get the same thing. One comment (this one) sounds like it should help but I'm not Ruby enough to understand what he's saying I should do.
Also, that whole thread is from 2011 and I have to assume something has changed since then. Any leads?
So I have a rails server which accepts json requests. I intend to use it as a server for my iphone app. I get a sign up fail no matter what.
my User Controller is
class UsersController < ApplicationController
respond_to :json
def create
#user = User.new(params[:user])
if #user.save
render :json => {:status => "200", :message => "Signed up successfully"}
else
render :json => {:status => "400", :message => "Failed"}
end
end
end
The url i sent in is
http://localhost:3000/sign_up.json?username=chalami&password=chalami&name=chalami&email=3020#gmail.com
I sent in the url through my browser and not through the app. I wanted to test it through the browser first.
With the posted url I get a
{"status":"400","message":"Failed"}
which should not be happening.
Here is my user.rb
class User < ActiveRecord::Base
attr_accessible :email, :name, :username
attr_accessor :password
before_save :encrypt_password
validates_uniqueness_of :username, :email
validates_presence_of :password, :on => :create
validates_presence_of :email, :username
def encrypt_password
if password.present?
self.password_salt = BCrypt::Engine.generate_salt
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
end
end
end
My database is empty so it cannot be that either email or username is taken
EDIT 1:
output from rake routes:
sign_up GET /sign_up(.:format) users#create
index GET /index(.:format) users#index
root / users#index
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
Here's the log
Started GET "/sign_up.json?username=chalami&password= [FILTERED]&name=chalami&email=3020#gmail.com" for 127.0.0.1 at 2013-05-28 00:40:44 +0700
Processing by UsersController#create as JSON
Parameters: {"username"=>"chalami", "password"=>"[FILTERED]", "name"=>"chalami", "email"=>"3020#gmail.com"}
(0.0ms) begin transaction
User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."username" IS NULL LIMIT 1
User Exists (0.0ms) SELECT 1 AS one FROM "users" WHERE "users"."email" IS NULL LIMIT 1
(0.0ms) rollback transaction
Completed 200 OK in 11ms (Views: 0.2ms | ActiveRecord: 0.6ms)
[2013-05-28 00:40:44] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
EDIT 2::
So as suggested in the comments, I should be using POST instead of GET and I should use curl. I see in my rake routes that there is a POST method with url /users .
so I do a curl on that
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"user":{"name":"name","username":"username","email":"email#email.com","password":"app123"}}' http://localhost:3000/users
and I get a whole load of output but could not create a User. Here is the output:
' http://localhost:3000/users
* About to connect() to localhost port 3000 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /users HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:3000
> Accept: application/json
> Content-type: application/json
> Content-Length: 93
>
* upload completely sent off: 93 out of 93 bytes
< HTTP/1.1 500 Internal Server Error
< Content-Type: text/html; charset=utf-8
< Content-Length: 15954
< X-Request-Id: 002af4460c3128e7a78bd10362bcb30f
< X-Runtime: 0.108395
< Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10)
< Date: Mon, 27 May 2013 17:56:09 GMT
< Connection: Keep-Alive
<
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Action Controller: Exception caught</title>
<style>
body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
font-family: helvetica, verdana, arial, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
white-space: pre-wrap;
}
a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
</style>
</head>
<body>
<h1>
ActiveModel::MassAssignmentSecurity::Error
in UsersController#create
</h1>
<pre>Can't mass-assign protected attributes: password</pre>
<p><code>Rails.root: /Users/chalamphongpandey/rails_projects/comboo</code></p>
<div id="traces">
Application Trace |
Framework Trace |
Full Trace
<div id="Application-Trace" style="display: block;">
<pre><code>app/controllers/users_controller.rb:8:in `new'
app/controllers/users_controller.rb:8:in `create'</code></pre>
</div>
<div id="Framework-Trace" style="display: none;">
<pre><code>activemodel (3.2.13) lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
activemodel (3.2.13) lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
activemodel (3.2.13) lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'
activemodel (3.2.13) lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment'
activerecord (3.2.13) lib/active_record/attribute_assignment.rb:75:in `assign_attributes'
activerecord (3.2.13) lib/active_record/base.rb:498:in `initialize'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.13) lib/active_support/callbacks.rb:414:in `_run__1456629456087302299__process_action__2823567861297586124__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__806197691580144289__call__628697914765895210__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'
railties (3.2.13) lib/rails/engine.rb:479:in `call'
railties (3.2.13) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/Users/chalamphongpandey/.rvm/rubies/ruby-1.9.3- p327/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/chalamphongpandey/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/chalamphongpandey/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'</code></pre>
</div>
<div id="Full-Trace" style="display: none;">
<pre><code>activemodel (3.2.13) lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
activemodel (3.2.13) lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
activemodel (3.2.13) lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'
activemodel (3.2.13) lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment'
activerecord (3.2.13) lib/active_record/attribute_assignment.rb:75:in `assign_attributes'
activerecord (3.2.13) lib/active_record/base.rb:498:in `initialize'
app/controllers/users_controller.rb:8:in `new'
app/controllers/users_controller.rb:8:in `create'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.13) lib/active_support/callbacks.rb:414:in `_run__1456629456087302299__process_action__2823567861297586124__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__806197691580144289__call__628697914765895210__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'
railties (3.2.13) lib/rails/engine.rb:479:in `call'
railties (3.2.13) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/Users/chalamphongpandey/.rvm/rubies/ruby-1.9.3- p327/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/chalamphongpandey/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/chalamphongpandey/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'</code></pre>
</div>
</div>
<h2 style="margin-top: 30px">Request</h2>
<p><b>Parameters</b>: <pre>{"user"=>{"name"=>"name",
"username"=>"username",
"email"=>"email#email.com",
"password"=>"[FILTERED]"}}</pre></p>
<p>Show session dump</p>
<div id="session_dump" style="display:none"><pre></pre></div>
<p>Show env dump</p>
<div id="env_dump" style="display:none"><pre>GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "application/json"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "localhost"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"</pre></div>
<h2 style="margin-top: 30px">Response</h2>
<p><b>Headers</b>: <pre>None</pre></p>
</body>
</html>
* Connection #0 to host localhost left intact
* Closing connection #0
From your error it says that Can't mass-assign protected attributes: password and from the looks of your user model you have made :password an attr_accessor. It is important to understand the differences between the two. The Accessor is a built in thing into Ruby that defies a getter method so that the attribute can be read. Whereas attr_accessible is a ActiveRecord mass-assignment method. The purpose of this is to allow you to pass values to a mass-assginment. You may benefit from reading the following: MassAssignmentSecurity. So what I recommend you to do is change attr_accessor :password to attr_accessible :password
Everything works fine until I push to heroku, I gathered that it has to do with diffirent ways mysql and postgres display the boolean values?
I am using Ruby 1.9.2p318 and Rails 3.2.2 with Mysql 5.2.35 on Max OSX
Here is the query I am trying to run
#special_offers = Wine.find(:all, :include => [:inventories], :conditions => ["inventories.special = ? AND inventories.warehouse_id IN (?)", "true", #wharehouses_array], :order => "inventories.updated_at DESC", :limit => 3)
It seems the problem lies with the inventories.special = ?, "true"
This works fine on mysql but not when I push to heroku, wich is using postgres
I have tried replacing the "true" with 1 and "1" and "t" and t and true but nothing seems to work?
UPDATE:
Heroku log file
2012-04-04T14:06:58+00:00 app[web.1]: [2012-04-04 14:06:58] INFO WEBrick 1.3.1
2012-04-04T14:06:58+00:00 app[web.1]: [2012-04-04 14:06:58] INFO WEBrick::HTTPServer#start: pid=1 port=54181
2012-04-04T14:06:58+00:00 app[web.1]: [2012-04-04 14:06:58] INFO ruby 1.9.2 (2011-07-09) [x86_64-linux]
2012-04-04T14:06:59+00:00 heroku[web.1]: State changed from starting to up
2012-04-04T14:07:01+00:00 app[web.1]: => Booting WEBrick
2012-04-04T14:07:01+00:00 app[web.1]: => Call with -d to detach
2012-04-04T14:07:01+00:00 app[web.1]: => Ctrl-C to shutdown server
2012-04-04T14:07:01+00:00 app[web.1]:
2012-04-04T14:07:01+00:00 app[web.1]: => Rails 3.2.2 application starting in production on http://0.0.0.0:54181
2012-04-04T14:07:01+00:00 app[web.1]:
2012-04-04T14:07:01+00:00 app[web.1]: Started GET "/" for 41.119.121.138 at 2012-04-04 14:07:01 +0000
2012-04-04T14:07:02+00:00 app[web.1]: Processing by HomeController#index as HTML
2012-04-04T14:07:03+00:00 app[web.1]: Rendered partials/_display_wines.html.erb (169.1ms)
2012-04-04T14:07:03+00:00 app[web.1]: Rendered partials/_display_wines.html.erb (0.0ms)
2012-04-04T14:07:03+00:00 app[web.1]: Rendered partials/_display_wines.html.erb (8.1ms)
2012-04-04T14:07:03+00:00 app[web.1]: Rendered home/index.html.erb within layouts/application (259.9ms)
2012-04-04T14:07:03+00:00 app[web.1]: Rendered partials/_header_bar.html.erb (6.5ms)
2012-04-04T14:07:03+00:00 app[web.1]: Rendered partials/_main_links.html.erb (0.3ms)
2012-04-04T14:07:03+00:00 app[web.1]: Rendered partials/_footer.html.erb (4.9ms)
2012-04-04T14:07:03+00:00 app[web.1]: Completed 200 OK in 1081ms (Views: 345.8ms | ActiveRecord: 175.7ms | Solr: 0.0ms)
2012-04-04T14:07:03+00:00 app[web.1]: cache: [GET /] miss
2012-04-04T14:07:03+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=1350ms status=200 bytes=36808
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/javascripts/jquery.js dyno=web.1 queue=0 wait=0ms service=137ms status=304 bytes=0
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/stylesheets/style1.css dyno=web.1 queue=0 wait=0ms service=179ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /stylesheets/style1.css] miss
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /javascripts/jquery.js] miss
+00:00 app[web.1]: cache: [GET /javascripts/script1.js] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/javascripts/script1.js dyno=web.1 queue=0 wait=0ms service=187ms status=304 bytes=0
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/javascripts/PIE.js dyno=web.1 queue=0 wait=0ms service=185ms status=304 bytes=0
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/javascripts/rails.js dyno=web.1 queue=0 wait=0ms service=189ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /javascripts/PIE.js] miss
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /javascripts/rails.js] miss
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/header_tile.png] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/header_tile.png dyno=web.1 queue=0 wait=0ms service=16ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/none.png] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/none.png dyno=web.1 queue=0 wait=0ms service=35ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/cybercellar_logo.jpg] miss
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/flags.png] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/flags.png dyno=web.1 queue=0 wait=0ms service=96ms status=304 bytes=0
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/cybercellar_logo.jpg dyno=web.1 queue=0 wait=0ms service=84ms status=304 bytes=0
2012-04-04T14:07:04+00:00 app[web.1]: cache: [GET /images/header_login.png] miss
2012-04-04T14:07:04+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/header_login.png dyno=web.1 queue=0 wait=0ms service=44ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/no_wine.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/no_wine.png dyno=web.1 queue=0 wait=0ms service=22ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/buttons2.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/buttons2.png dyno=web.1 queue=0 wait=0ms service=19ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/find_wine_wrap.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/find_wine_wrap.png dyno=web.1 queue=0 wait=0ms service=22ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/comment.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/comment.png dyno=web.1 queue=0 wait=0ms service=5ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/bullet.png] miss
4:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/bullet.png dyno=web.1 queue=0 wait=0ms service=13ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/buttons.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/buttons.png dyno=web.1 queue=0 wait=0ms service=12ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/links_bar.png] miss
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/hr_light.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/hr_light.png dyno=web.1 queue=0 wait=0ms service=12ms status=304 bytes=0
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/links_bar.png dyno=web.1 queue=0 wait=0ms service=17ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/cart_background.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/cart_background.png dyno=web.1 queue=0 wait=0ms service=4ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/home_page_image.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/home_page_image.png dyno=web.1 queue=0 wait=0ms service=6ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/find_wine.png] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/find_wine.png dyno=web.1 queue=0 wait=0ms service=10ms status=304 bytes=0
2012-04-04T14:07:05+00:00 app[web.1]: cache: [GET /images/footer_tile.jpg] miss
2012-04-04T14:07:05+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/footer_tile.jpg dyno=web.1 queue=0 wait=0ms service=7ms status=304 bytes=0
2012-04-04T14:07:06+00:00 app[web.1]: cache: [GET /images/social.png] miss
2012-04-04T14:07:06+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/hr_dark.jpg dyno=web.1 queue=0 wait=0ms service=5ms status=304 bytes=0
2012-04-04T14:07:06+00:00 app[web.1]: cache: [GET /images/hr_dark.jpg] miss
2012-04-04T14:07:06+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/social.png dyno=web.1 queue=0 wait=0ms service=6ms status=304 bytes=0
2012-04-04T14:07:06+00:00 app[web.1]: cache: [GET /images/credit_cards.png] miss
2012-04-04T14:07:06+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/credit_cards.png dyno=web.1 queue=0 wait=0ms service=14ms status=304 bytes=0
2012-04-04T14:07:06+00:00 app[web.1]: cache: [GET /images/money_back.png] miss
2012-04-04T14:07:06+00:00 heroku[router]: GET stormy-fog-6888.herokuapp.com/images/money_back.png dyno=web.1 queue=0 wait=0ms service=5ms status=304 bytes=0
Schema file: for the inventories table
create_table "inventories", :force => true do |t|
t.integer "wine_id"
t.integer "warehouse_id"
t.integer "stock"
t.float "price"
t.integer "quantity_id"
t.timestamp "created_at"
t.timestamp "updated_at"
t.boolean "available", :default => false
t.boolean "discount", :default => false
t.string "markupprofile_id", :limit => 45
t.string "discountprofile_id", :limit => 45
t.float "discount_price"
t.boolean "special", :default => false
end
Use the actual TrueClass, not a string, and Rails will translate it into the correct query for you.
Correct:
"inventories.special = ?", true
Incorrect:
"inventories.special = ?", "true"
It's not throwing an error because the second one still produces a valid query, it's just looking for records where special is a string with the actual t-r-u-e characters in it.