Welcome Guest | Login

validates_acceptance_of

Hi,

I'm having trouble with validates_acceptance_of.

I have this in my user model:

validates_acceptance_of   :terms, :allow_nil => false, :accept => "yes", :message => "Você deve ler e aceitar os termos de uso e a política de privacidade"
i created 2 methods on the user controller, "terms" and "privacy", just to render the corresponding views "terms.html.erb" and "privacy.html.erb"

Ok, that explained, the problem i'm having is that it's always asking to login before beeing able to view it.

In my new.html.erb view (the user signup form):
(...)
<%= check_box_tag 'terms', 'yes', false%>
Eu sou maior de 14 anos e realmente li os <%= link_to "Termos de Uso", { :action => "terms", :title => 'Termos e condições' } %> e a <%= link_to " Política de Privacidade", { :action => "privacy", :title => 'Política de Privacidade' } %>
"I am older than 14 years and i really read the terms and the privacy".
Nervermind the portuguese as the code looks pretty straightforward :)

Now on my user_controller i have the RESTFUL for authentication:
  before_filter :not_logged_in_required, :only => [:new, :create, :terms, :privacy] 
 before_filter :login_required, :only => [:show, :edit, :update, :index]
Note that i already added :terms and :privacy, but it still asks for login...

what am i missing here? i ran out of options to check
leave suggestions please!

thanks :D

2008-06-03 01:35 PM

code is poetry~
Assuming this is not a matter of simply restarting your server to pick up the changes, what does your routes.rb file look like for the user resource?  Do you have to put the terms and privacy actions in your user controller?  

2008-06-03 06:07 PM

map.root :controller => "home", :action => "index"
 
 # See how all your routes lay out with "rake routes"
 map.resources :home
 
 map.resources :users, :member => { :enable => :put } do |users|
   users.resource :account  
 end
 
 map.resource :session
 map.resource :password
(...)
Those are the resources, do i need to add the :privacy and :terms? if yes, where? i don't get it why is that necessary.

And i just put the actions in the user controller so it render the user/privacy and user/terms views..i tought that would be the easier way? is there another way i can load a view (not template) without assigning to an action?

it doesn't hurt to have 2 blank actions there (only if that is exactly why it's not working for me...)

2008-06-05 12:56 PM

code is poetry~
Hi there,

It seems like there is an index.html file present inside the public folder, then "map.root" specified in the config/routes.rb will not be taken. Also do the index action of the user requires authentication?  
Because the request from the URL http://domain.com/users will go to the users/index page and if there is any authentication then the default page of users controller won't be loaded.

>>And i just put the actions in the user >controller so it render the user/privacy and >user/terms views..i tought that would be the >easier way? is there another way i can load a >view (not template) without assigning to an >action?

You can access the actions as users/terms and users/privacy. You can't load a view without assigning to an action. Is the terms and privacy is loading after providing the required authentication?

2008-06-05 09:12 PM

Hi,

i'm very sorry for the late reply

Vinayan, the index.html file is itentional as well as the map.root not beeing taken. it's just a splash screen.

and i can't access users/terms, it redirects to users/show (??) after i log in




also, i already added index in login_not_required

2008-06-13 02:39 AM

code is poetry~
Hi Marcobr,

Please execute a command "rake routes" and verify if all the actions corresponding to the controllers are displaying. In the domain.com/users page, while clicking the " Termos de Uso (Terms) " button, the url is changed to domain.com/users#. Also the links given in  domain.com/users are not directing any where.

>and i can't access users/terms, it redirects to users/show (??) >after i log in

What is the logs updating while accessing users/terms after logging in. You can also try with "before_filter" with "except" option if  the option "only" is not giving the right results.

2008-06-14 03:24 PM

oh on the /users, those links are all blank (#), nevermind them.. :P

i'm sorry i should be more specific, try this:

domain.com/users/new
those 2 links before the submit button are the "terms" and "privacy", if you click them it will ask you for to log in
(or try to register and click after logging in if you are interested)

the log output:
Processing UsersController#show (for 85.8.0.76 at 2008-06-15 04:28:36) [GET]
 Session ID: f4b01e564f9444098c92801a00152986
 Parameters: {"action"=>"show", "id"=>"privacy", "controller"=>"users"}
Rendering template within layouts/application
Rendering users/show
Completed in 0.00228 (438 reqs/sec) | Rendering: 0.00184 (80%) | DB: 0.00000 (0%) | 200 OK http://www.domain.com/users/privacy][/code]

privacy is the id?? i tought it should be the action

the "except" option didn't work, but after checking the log it seems like nothing will work until the controller thinks that the action is show instead of privacy (or terms)

2008-06-15 04:39 AM

code is poetry~
Correct me if I'm wrong here - a bit hard to troubleshoot this - but don't you need

map.resources :users, :member => { :enable => :put, :privacy => :get, :terms => :get } do |users|
   users.resource :account  
 end

2008-06-15 02:48 PM

hi William,

I don't know if i need a route or not, i'm new to this

but i don't get it why would that be necessary if it's just a matter of calling an action to render a view with a lorem ipsum text..

anyway, i tried adding that and still the same thing

and i was checking my log, there are 3 weird files there now:

"users}", "privacy," and  "show," (just like that with the commas and the '{' )

2008-06-16 05:24 AM

code is poetry~
Let's step back a moment.  Normally if you want to put an action in the users controller you would expect a URL like /users/17/terms

if your terms and privacy are for everyone then you should have

/terms
/privacy

as separate routes and you could put the action in your application controller or another controller like "appwidecontent" or something that you could set the route to.

Let us know if you need more help with this.
~William

2008-06-16 10:57 AM

oohh now i get it..

i was trying to do /users/terms and without and id it was somehow going to /users/show/terms

thanks for the explanation William, and thanks for your help Vinayan, you guys have been pretty patient ^^

now it's working after adding these 2 lines in routes

  map.terms '/terms', :controller => 'users', :action => 'terms'
 map.privacy '/privacy', :controller => 'users', :action => 'privacy'
thanks again.

2008-06-16 12:52 PM

code is poetry~

Hello Guest! In order to post you must be an active client with us, please log in or sign up today!