Original Question
I'm running Rails 3.0.1 on Ruby 1.9.2. Here are the relevant model, controller, and view.
Code
user.rb:
class User < ActiveRecord::Base
belongs_to :directory
attr_accessor :new_password, :new_password_confirmation
validates_confirmation_of :new_password, :if => :password_changed?
before_save :hash_password, :if => :password_changed?
def self.authenticate(login, password)
# Check to see if the user exists
if user = find_by_login(login)
# If this is an directory user, authenticate them against their directory
if user.directory
return directory_auth user, password
# Otherwise, authenticate them against the local database
elsif user.hash == Digest::SHA2.hexdigest(user.salt + password)
return user
end
end
return nil
end
def password_changed?
!#new_password.blank?
end
private
def hash_password
self.salt = ActiveSupport::SecureRandom.base64 8
self.hash = Digest::SHA2.hexdigest(self.salt + #new_password)
end
def self.directory_auth(user, password)
directory = user.directory
directory.bind['%s'] = user.login
ldap = Net::LDAP.new
if directory.use_simple_tls?
ldap.encryption :simple_tls
end
ldap.host = directory.host
ldap.port = directory.port
ldap.auth directory.bind, password
return user if ldap.bind
return nil
end
end
users_controller.rb:
class UsersController < ApplicationController
def index
#users = User.all
end
def show
#user = User.find params[:id]
end
def new
#user = User.new
end
def create
#user = User.new params[:user]
if #user.save
flash[:notice] = "#{#user.login} was created"
redirect_to #user
else
flash[:notice] = 'The user could not be created'
render :action => 'new'
end
end
def edit
#user = User.find params[:id]
end
def update
#user = User.find params[:id]
#user.attributes = params[:user] # this works
# #user.update_attributes params[:user] # this does NOT work
if #user.save # I realize this is redundant if update_attributes is working
flash[:notice] = "#{#user.login} was updated"
redirect_to #user
else
flash[:notice] = 'The user could not be updated'
render :action => 'edit'
end
end
def destroy
#user = User.find params[:id]
#user.destroy
flash[:notice] = "#{#user.login} was deleted"
redirect_to users_url
end
end
users.html.erb:
<%= form_for #user do |f| %>
<%= f.label :login %>:
<%= f.text_field :login %>
<br>
<%= f.label :new_password %>:
<%= f.password_field :new_password %>
<br>
<%= f.label :new_password_confirmation %>:
<%= f.password_field :new_password_confirmation %>
<br>
<% if directories = Directory.all.empty? %>
No directories defined. You can <%= link_to 'add a directory', new_directory_path %>.
<% else %>
<%= f.label :directory_id %>:
<%= f.collection_select :directory_id, Directory.all, :id, :name, { :include_blank => 'None' } %>
<% end %>
<br>
<%= f.label :admin, 'Administrator?' %>:
<%= f.check_box :admin %>
<br>
<%= f.submit %>
<% end %>
schema.rb:
ActiveRecord::Schema.define(:version => 20101107005603) do
create_table "directories", :force => true do |t|
t.string "host"
t.string "bind"
t.boolean "use_simple_tls"
t.integer "port"
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", :force => true do |t|
t.string "login"
t.string "hash"
t.string "salt"
t.boolean "admin"
t.integer "directory_id"
t.datetime "created_at"
t.datetime "updated_at"
end
end
I have another model/controller/view for directories that is very similar, but doesn't have virtual accessors or other model ids, and update_attributes works fine in it. I did a quick test app with rails g scaffold users name:string password:string and all CRUD actions work fine.
This was driving me nuts! I found a workaround, but I really want to understand why update_attributes doesn't work here. When I run the update action, I get this:
TypeError in UsersController#update
can't convert nil into Integer
Rails.root: /home/force/proj
app/controllers/users_controller.rb:34:in `update'
Full Stack Trace
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/database_statements.rb:318:in `uniq'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/database_statements.rb:318:in `commit_transaction_records'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/database_statements.rb:165:in `transaction'
activerecord (3.0.1) lib/active_record/transactions.rb:204:in `transaction'
activerecord (3.0.1) lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
activerecord (3.0.1) lib/active_record/persistence.rb:126:in `update_attributes'
app/controllers/users_controller.rb:34:in `update'
actionpack (3.0.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.1) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.1) lib/active_support/callbacks.rb:435:in `_run__805567340__process_action__482539529__callbacks'
activesupport (3.0.1) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.1) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.1) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.1) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.1) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.1) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.1) lib/action_controller/metal.rb:133:in `dispatch'
actionpack (3.0.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.1) lib/action_controller/metal.rb:173:in `block in action'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:103:in `optimized_each'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:492:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/cookies.rb:287:in `call'
activerecord (3.0.1) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.1) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.1) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.1) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.1) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.1) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `block in call'
:10:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.1) lib/rails/application.rb:168:in `call'
railties (3.0.1) lib/rails/application.rb:77:in `method_missing'
railties (3.0.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service'
/home/force/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/force/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/force/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Request Parameters
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"OvMUeM9hqfPASC0NS+Th07GELu6B+dQCCTtm3gWdJE4=",
"user"=>{"login"=>"local",
"new_password"=>"[FILTERED]",
"new_password_confirmation"=>"[FILTERED]",
"directory_id"=>"",
"admin"=>"0"},
"commit"=>"Update User",
"id"=>"13"}
Full Source Code
If you'd like to give it a try, you can download the full source at http://github.com/sidewaysmilk/deezy and edit app/controllers/users_controller.rb to use #user.update_attributes params[:user] in the update action.
OK. I feel really stupid. I'm surprised nobody caught this.
In my model, I name one of my attributes. hash, so to access it, I would say #user.hash.
ActiveRecord::Base#hash is already defined!
So I screwed up. When ActiveRecord was attempting to execute the transaction, it was trying to set a value like
#user.hash = password_hash
ActiveRecord::Base#hash= expects an integer, and password_hash outputs a String if the password is changed, and nil otherwise.
So never name a column hash! Check the documentation when you're picking column names to avoid collisions.
It looks like what may be the problem is that the user id is a primary key and somehow that is being attempted to be updated. What is the error message you get if you use the 'bangversion ofupdate_attributes:update_attributes!` ?
Without a full stack trace it's hard to say, but the error message "can't convert nil into Integer" is your key thing to track down. Likewise we want see the logs for a request that's failing. I think the Parameters: line of the log might shed light on the issue.
Update Below:
Can you pass the same params successfully to #user.update_attributes in the rails console?
rails console
user = User.find(42) # whatever a good test user's id is
user_params = {"login"=>"local", "new_password"=>"supersecret", "new_password_confirmation"=>"supersecret", "directory_id"=>"", "admin"=>"0"}
user.update_attributes!(user_params)
Does that behave any differently?
Related
I am trying to add a new Action Mailer to my app and when I navigated to connections/new I received this error message:
Circular dependency detected while autoloading constant
ConnectionsController
full trace
activesupport (4.1.0) lib/active_support/dependencies.rb:478:in `load_missing_constant'
activesupport (4.1.0) lib/active_support/dependencies.rb:180:in `const_missing'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:238:in `const_get'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:238:in `block in constantize'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:236:in `each'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:236:in `inject'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:236:in `constantize'
activesupport (4.1.0) lib/active_support/dependencies.rb:552:in `get'
activesupport (4.1.0) lib/active_support/dependencies.rb:583:in `constantize'
actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:66:in `controller'
actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:44:in `call'
actionpack (4.1.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:676:in `call'
warden (1.2.4) lib/warden/manager.rb:35:in `block in call'
warden (1.2.4) lib/warden/manager.rb:34:in `catch'
warden (1.2.4) lib/warden/manager.rb:34:in `call'
rack (1.5.5) lib/rack/etag.rb:23:in `call'
rack (1.5.5) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.5) lib/rack/head.rb:11:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.0) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.0) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
rollbar (2.4.0) lib/rollbar/middleware/rails/rollbar.rb:24:in `block in call'
rollbar (2.4.0) lib/rollbar.rb:842:in `scoped'
rollbar (2.4.0) lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
rollbar (2.4.0) lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
actionpack (4.1.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.0) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
railties (4.1.0) lib/rails/engine.rb:514:in `call'
railties (4.1.0) lib/rails/application.rb:144:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
controllers/connections_controller.rb
class ConnectionionsController < ApplicationController
def new
#connection = connection.new
end
def create
#connection = Connection.new(connection_params)
if #connection.save
name = params[:connection][:your_name]
email = params[:connection][:email]
body = params[:connection][:mentors_name, :mentees_name]
connectionMailer.connection_email(name, email, body).deliver
flash[:success] = "Message sent. Someone at Jr. Dev Mentoring will respond to your message soon. Thank you."
redirect_to new_connection_path
else
flash[:danger] = "Error occured, message has not been sent. You must complete all form fields"
redirect_to new_connection_path
end
end
private
def connection_params
params.require(:connection).permit(:your_name, :email, :mentors_name, :mentees_name)
end
end
mailers/connection_mailer.rb
class ConnectionsMailer < ActionMailer::Base
default to: 'info#jrdevmentoring.com'
def connection_email(name, email, body)
#name = name
#email = email
#body = body
mail(from: email, subject: 'Jr. Dev Mentoring Connect Form Message')
end
end
models/connection.rb
class Connection < ActiveRecord::Base
validates :your_name, presence: true
validates :email, presence: true
end
views/connections/new.html.erb
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1 class="text-center">Let's Connect</h1>
<p class="text-center">I'd like to connect</p>
<div class="well">
<%= form_for #connection do |f| %>
<div class="form-group">
<%= f.label :your_name %>
<%= f.text_field :your_name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group, 'Mentors Name'">
<%= f.label :comments %>
<%= f.text_area :mentors_name, class: 'form-control' %>
</div>
<div class="form-group, 'Mentees Name'">
<%= f.label :comments %>
<%= f.text_area :mentees_name, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default' %>
<% end %>
</div>
</div>
</div>
views/connection_mailer/connection_email.html.erb
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>You have received a message from the Jr. Dev Mentoring site's connect form, from <%= "#{ #name }, #{ #email }." %></p>
<p><%= #body %></p>
</body>
</html>
db/migrate
class CreateConnections < ActiveRecord::Migration
def change
create_table :connections do |t|
t.string :your_name
t.string :email
t.text :mentors_name
t.text :mentees_name
t.timestamps
end
schema
create_table "connections", force: true do |t|
t.string "your_name"
t.string "email"
t.text "mentors_name"
t.text "mentees_name"
t.datetime "created_at"
t.datetime "updated_at"
end
routes
Rails.application.routes.draw do
devise_for :users,:controllers => { :registrations => "users/registrations" }
resources :users do
resource :profile
end
resources :connections
resources :contacts
get '/about' => 'pages#about'
namespace :mentee do
root 'pages#home'
get '/mentor_profiles' => 'profiles#mentor_profiles'
end
namespace :mentor do
root 'pages#home'
get '/mentee_profiles' => 'profiles#mentee_profiles'
end
root 'pages#home'
I found several spelling and capitalization errors in my connections_controller.rb file
replaced class ConnectionionsController < ApplicationController with class ConnectionsController < ApplicationController
replaced #connection = connection.new with #connection = Connection.new
replaced connectionMailer.connection_email(name, email, body).deliver with ConnectionMailer.connection_email(name, email, body).deliver
I am able to delete the links that are assigned to each user, unless they are voted upon. If a link has any votes on it the delete method being called no longer works.
Here is a link to the website deployed on heroku. If you sign up. submit a link, vote it up or down and then try to delete you will see the error I am experiencing.
https://salty-eyrie-2549.herokuapp.com/
EDIT: After launching the app live i found the code works as long as the app is not being hosted locally... Very Strange...
This is the error I am getting.
NoMethodError in LinksController#destroy
undefined method `name' for nil:NilClass
Extracted source (around line #59):
# DELETE /links/1.json
def destroy
#link.destroy
respond_to do |format|
format.html { redirect_to links_url, notice: 'Link was successfully destroyed.' }
format.json { head :no_content }
Rails.root: /Users/ipbyrne/FirstRailsApp/raddit
Application Trace | Framework Trace | Full Trace
app/controllers/links_controller.rb:59:in `destroy'
Request
Parameters:
{"_method"=>"delete",
"authenticity_token"=>"3JyyNGNPHhdVcQ7tZQ64t+ouQjiNFnwxQXw25fgJGX4=",
"id"=>"5"}
I am using the act_as_votable ruby gem.
The first block below is my show.html.erb where the destroy method is being called from
The second block is my links_controller.rb file.
<div class="page-header">
<h1><%= #link.title %><br> <small>Submitted by <%= #link.user.name %></small></h1>
</div>
<div class="btn-group">
<%= link_to 'Visit URL', #link.url, class: "btn btn-primary" %>
</div>
<div class="btn-group pull-right">
<%= link_to like_link_path(#link), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-up"></span>
Upvote
<%= #link.get_upvotes.size %>
<% end %>
<%= link_to dislike_link_path(#link), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-down">
Downvote
<%= #link.get_downvotes.size %>
<% end %>
</div>
<% if #link.user == current_user -%>
<div class="btn-group">
<%= link_to 'Edit', edit_link_path(#link), class: "btn btn-default" %>
<%= link_to 'Destroy', #link, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-default" %>
</div>
<% end %>
<h3 class="comments_title">
<%= #link.comments.count %> Comments
</h3>
<div id="comments">
<%= render :partial => #link.comments %>
</div>
<%= simple_form_for [#link, Comment.new] do |f| %>
<div class="field">
<%= f.text_area :body, class: "form-control" %>
</div>
<br>
<%= f.submit "Add Comment", class: "btn btn-primary" %>
<% end %>
class LinksController < ApplicationController
before_action :set_link, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
before_action :authorized_user, only: [:edit, :update, :destroy]
# GET /links
# GET /links.json
def index
#links = Link.all
end
# GET /links/1
# GET /links/1.json
def show
end
# GET /links/new
def new
#link = current_user.links.build
end
# GET /links/1/edit
def edit
end
# POST /links
# POST /links.json
def create
#link = current_user.links.build(link_params)
respond_to do |format|
if #link.save
format.html { redirect_to #link, notice: 'Link was successfully created.' }
format.json { render :show, status: :created, location: #link }
else
format.html { render :new }
format.json { render json: #link.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /links/1
# PATCH/PUT /links/1.json
def update
respond_to do |format|
if #link.update(link_params)
format.html { redirect_to #link, notice: 'Link was successfully updated.' }
format.json { render :show, status: :ok, location: #link }
else
format.html { render :edit }
format.json { render json: #link.errors, status: :unprocessable_entity }
end
end
end
# DELETE /links/1
# DELETE /links/1.json
def destroy
#link.destroy
respond_to do |format|
format.html { redirect_to links_url, notice: 'Link was successfully destroyed.' }
format.json { head :no_content }
end
end
def upvote
#link = Link.find(params[:id])
#link.upvote_by current_user
redirect_to :back
end
def downvote
#link = Link.find(params[:id])
#link.downvote_from current_user
redirect_to :back
end
private
# Use callbacks to share common setup or constraints between actions.
def set_link
#link = Link.find(params[:id])
end
def authorized_user
#link = current_user.links.find_by(id: params[:id])
redirect_to links_path, notice: "Not authorized to edit this link" if #link.nil?
end
# Never trust parameters from the scary internet, only allow the white list through.
def link_params
params.require(:link).permit(:title, :url)
end
end
Full Trace Error
activerecord (4.0.0) lib/active_record/associations/has_many_association.rb:80:in `cached_counter_attribute_name'
activerecord (4.0.0) lib/active_record/associations/has_many_association.rb:103:in `inverse_updates_counter_cache?'
activerecord (4.0.0) lib/active_record/associations/has_many_association.rb:113:in `delete_records'
activerecord (4.0.0) lib/active_record/associations/collection_association.rb:493:in `remove_records'
activerecord (4.0.0) lib/active_record/associations/collection_association.rb:486:in `block in delete_or_destroy'
activerecord (4.0.0) lib/active_record/associations/collection_association.rb:152:in `block in transaction'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:200:in `transaction'
activerecord (4.0.0) lib/active_record/transactions.rb:209:in `transaction'
activerecord (4.0.0) lib/active_record/associations/collection_association.rb:151:in `transaction'
activerecord (4.0.0) lib/active_record/associations/collection_association.rb:486:in `delete_or_destroy'
activerecord (4.0.0) lib/active_record/associations/collection_association.rb:247:in `destroy'
activerecord (4.0.0) lib/active_record/associations/collection_association.rb:170:in `destroy_all'
activerecord (4.0.0) lib/active_record/associations/has_many_association.rb:26:in `handle_dependency'
activerecord (4.0.0) lib/active_record/associations/builder/association.rb:97:in `has_many_dependent_for_votes_for'
activesupport (4.0.0) lib/active_support/callbacks.rb:377:in `_run__4103742494544083763__destroy__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
activerecord (4.0.0) lib/active_record/callbacks.rb:289:in `destroy'
activerecord (4.0.0) lib/active_record/transactions.rb:265:in `block in destroy'
activerecord (4.0.0) lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
activerecord (4.0.0) lib/active_record/transactions.rb:209:in `transaction'
activerecord (4.0.0) lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
activerecord (4.0.0) lib/active_record/transactions.rb:265:in `destroy'
app/controllers/links_controller.rb:59:in `destroy'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:443:in `_run__1823692881447443679__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.5) lib/rack/etag.rb:23:in `call'
rack (1.5.5) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.5) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__1414070385979111640__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/Users/ipbyrne/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/ipbyrne/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/ipbyrne/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Link.rb
class Link < ActiveRecord::Base
acts_as_votable
belongs_to :user
has_many :comments
end
Schema
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150722133429) do
create_table "comments", force: true do |t|
t.integer "link_id"
t.text "body"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "comments", ["link_id"], name: "index_comments_on_link_id"
add_index "comments", ["user_id"], name: "index_comments_on_user_id"
create_table "links", force: true do |t|
t.string "title"
t.string "url"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
add_index "links", ["user_id"], name: "index_links_on_user_id"
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
create_table "votes", force: true do |t|
t.integer "votable_id"
t.string "votable_type"
t.integer "voter_id"
t.string "voter_type"
t.boolean "vote_flag"
t.string "vote_scope"
t.integer "vote_weight"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope"
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope"
end
Link Model
class Link < ActiveRecord::Base
acts_as_votable
belongs_to :user
has_many :comments
end
Sounds like you're unable to delete it because the link has associated votes. You will have to update the relationships in your Link model so that it allows allow_destroy: true, in which case it will delete the associations as well.
The error must be in your index.html.erb file. You are calling 'name' on some nil object.
I'm geolocating the user with geocoder and storing the value I get in the User's table (in a attribute called user_country_name).
I am sure it has nothing to do with geocoder but I don't manage to simply edit the country in User Account page.
I tried to edit the email and the passwoird and it works but not the other custom fields i added compared to Devise basic form.
I think I've done all needed to update account attributes in Rails 4 but keep getting this error for 2 whole days!
ActionController::UnpermittedParameters at /
found unpermitted parameters: user_country_name
Here is my form for User info edit
<%= semantic_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :class => 'form-vertical' }) do |f| %>
<%= f.semantic_errors %>
<%= f.inputs do %>
<%= f.input :email, :required => true %>
<%= f.input :user_country_name,
:as => :select,
:collection => COUNTRIES, # sends to a constant I have with all countries
:prompt => true
%>
<%= f.input :password, :input_html => { :autocomplete => "off" }, :hint => t("devise.registrations.edit_account_page.leave_blank_if_dont_want_to_change"), :required => false %>
<%= f.input :password_confirmation, :required => false %>
<% end %>
<%= f.actions do %>
<div>
<%= f.action :submit, :label => t("devise.registrations.edit_account_page.update"), :button_html => { :class => 'btn-primary' } %>
</div>
<div class="half-right-small return-login">
<%= link_to t("directions.back"), :back %>
</div>
<% end %>
<% end %>
here is my application controller
class ApplicationController < ActionController::Base
protect_from_forgery
include CountrySetter # handle localization through ip lookup and the I18n used
include LocaleSetter
# handle Cancan authorization exception
rescue_from CanCan::AccessDenied do |exception|
exception.default_message = t("errors.application_controller_exception_messages.only_open_to_admin")
if current_user # if it's user redirect to main HP
redirect_to root_path, :alert => exception.message
else
redirect_to customerinterface_path, :alert=> exception.message
end
end
before_filter :configure_permitted_parameters, if: :devise_controller?
private
before_filter :authenticate_user_from_token!
before_filter :authenticate_customer_from_token!
def authenticate_user_from_token!
user_email = params[:user_email].presence
user = user_email && User.find_by_email(user_email)
if user && Devise.secure_compare(user.authentication_token, params[:user_token])
sign_in user, store: false # we are signing in user if it exists. sign_in is devise method to sign in any user
redirect_to root_path # now we are redirecting the user to root_path i.e our homepage
end
end
protected
def configure_permitted_parameters
[:sign_up, :account_update].each do |sanitize_me|
devise_parameter_sanitizer.for(sanitize_me) do |u|
u.permit(:email, :password, :password_confirmation, :user_country_name)
end
end
end
def devise_parameter_sanitizer
if resource_class == User
UserParameterSanitizer.new(User, :user, params)
else # for customers
CustomerParameterSanitizer.new(Customer, :customer, params)
end
end
end
and finally the RegistrationsController form Devise:
class RegistrationsController < Devise::RegistrationsController
def update
# added for upgrade to Rails 4
account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
# required for settings form to submit when password is left blank
if account_update_params[:password].blank?
account_update_params.delete("password")
account_update_params.delete("password_confirmation")
end
#user = User.find(current_user.id)
if #user.update(account_update_params) # Rails 4 .update introduced with same effect as .update_attributes
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case his password changed
sign_in #user, :bypass => true
redirect_to after_update_path_for(#user)
else
render "edit"
end
end
# for Rails 4 Strong Parameters
def resource_params
params.require(:user).permit(:email, :password, :password_confirmation, :current_password, :user_country_name)
end
private :resource_params
# used to update user-country by ip lookup when user signs up and associate newly signed-up user with a country
# source - stackoverflow.com/questions/24294169/devise-sign-up-how-to-save-an-attribute-without-having-a-form-field-for-it-ra
protected
def after_sign_up_path_for(resource)
resource.update(user_country_name: set_country) #use concerns/CountrySetter loaded by ApplicationController
root_path
end
end
EDIT
To answer some comments asking for the Route
MyApp::Application.routes.draw do
# redundancy with below standard users 'root to' code. Goal: to easily be able to change
# the page if decide one day that users should see a different page when they log in
# used to be a bug- solved with: https://github.com/plataformatec/devise/issues/2393#issuecomment-17544388
authenticated :user do
root to: 'static_pages#home', as: :authenticated_root
end
# Homepage for unauthenticated users
# used to be a bug- solved with: https://github.com/plataformatec/devise/issues/2393#issuecomment-17544388
unauthenticated do
root to: 'static_pages#home' # , as: :unauthenticated_root
end
# Routes for users
devise_for :users,
:token_authentication_key => 'authentication_key',
:controllers => { confirmations: 'confirmations',
registrations: 'registrations',
sessions: 'sessions',
passwords: 'passwords',
unlocks: 'unlocks' },
path: '', # inspired by Nitish solution to make devise urls custom (source: tackoverflow.com/questions/19889570/rails-devise-user-registration-route-post)
path_names: { :sign_in => "signin",
:sign_out => "logout",
:sign_up => "signup" }
resources :users
# Routes for customers
devise_for :customers,
controllers: { registrations: 'customers/registrations', # inspired by stackoverflow.com/questions/20913157/devise-views-with-multiple-models
confirmations: 'customers/confirmations',
sessions: 'customers/sessions',
passwords: 'customers/passwords',
unlocks: 'customers/unlocks' },
path: 'advertiser', # inspired by Nitish solution to make devise urls custom (source: tackoverflow.com/questions/19889570/rails-devise-user-registration-route-post)
path_names: { :sign_in => "signin",
:sign_out => "logout",
:sign_up => "signup" }
# Routes for the interface with reportings and private data for Customers
# Customers interface HP can be accessed at /campaigns
match '/customerinterface',
to: 'clientreporting_pages#index',
path: 'campaigns',
via: 'get'
# Routes for all managed by Active Admin (deals creation, prizes creation...)
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
# Static Pages
match '/help', to: 'static_pages#help', path: 'help', via: 'get'
match '/aboutus', to: 'static_pages#aboutus', path: 'about-us', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
match '/howitworks', to: 'static_pages#howitworks', path: 'about', via: 'get'
match '/globalpresence', to: 'static_pages#globalpresence',path: 'global', via: 'get'
And here is the detailed log of error I get in my local console
Started PUT "/" for 127.0.0.1 at 2014-10-08 19:55:50 +0200
Processing by RegistrationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"geygeyegyegyegyegeykd7NwrVyAw=", "user"=>{"email"=>"emailtest#gmail.com", "user_country_name"=>"Germany", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"<span class="}
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 457 ORDER BY "users"."id" ASC LIMIT 1
Completed 500 Internal Server Error in 7ms
ActionController::UnpermittedParameters - found unpermitted parameters: user_country_name:
actionpack (4.0.5) lib/action_controller/metal/strong_parameters.rb:372:in `unpermitted_parameters!'
actionpack (4.0.5) lib/action_controller/metal/strong_parameters.rb:270:in `permit'
devise (3.2.4) lib/devise/parameter_sanitizer.rb:66:in `permit'
devise (3.2.4) lib/devise/parameter_sanitizer.rb:58:in `account_update'
devise (3.2.4) lib/devise/parameter_sanitizer.rb:77:in `default_sanitize'
devise (3.2.4) lib/devise/parameter_sanitizer.rb:24:in `sanitize'
app/controllers/registrations_controller.rb:11:in `update'
actionpack (4.0.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.5) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.5) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.5) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.5) lib/active_support/callbacks.rb:483:in `_run__3174996646979711185__process_action__callbacks'
activesupport (4.0.5) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.5) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.5) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.5) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.5) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.5) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.5) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.0.5) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.5) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.5) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.5) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.5) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.5) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.5) lib/action_dispatch/routing/mapper.rb:44:in `call'
actionpack (4.0.5) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.5) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.5) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:674:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.5) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.5) lib/active_record/migration.rb:373:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.5) lib/active_support/callbacks.rb:373:in `_run__2636980444171422651__call__callbacks'
activesupport (4.0.5) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.5) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
actionpack (4.0.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.5) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.5) lib/rails/engine.rb:511:in `call'
railties (4.0.5) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/me/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/me/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/me/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
EDIT #2
I tried everything that you guys proposed but nothing worked. then i tried one thing: I removed devise_parameter_sanitizer. then it works!! but should/can i remove this without compromising the security of the app? isn't this block important?
Here is the block I removed:
def devise_parameter_sanitizer
if resource_class == User
UserParameterSanitizer.new(User, :user, params)
else # for customers
CustomerParameterSanitizer.new(Customer, :customer, params)
end
end
What does it tell me about the problem ? maybe it's an important clue to the real bug but i don't get it:)
Many thanks for any help!
can you try this please
application controller
before_action :configure_permitted_parameters, if: :devise_controller?
and
application Controller
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << [your params]
devise_parameter_sanitizer.for(:account_update) << [your params]
end
Registrations controller
<!-- REMOVE -->
# added for upgrade to Rails 4
account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
# for Rails 4 Strong Parameters
def resource_params
params.require(:user).permit(:email, :password, :password_confirmation, :current_password, :user_country_name)
end
private :resource_params
let me know how this works out for you, you seem to be declaring your permitted params too many times in different places
My solution for this was to :
Create a true rest controllers/users_controller and to use Devise controllers just for controllers/users/registration_controllerand controllers/users/sessions_controller.
Unset devise control of create/edit un routes.rb
devise_for :users, controllers: { registrations: "users/registrations",
sessions: "users/sessions" }
resources :users
Answer Update
In Rails 4 you must permit all parameters with params.permit(params_list_to_allow) or for rapid upgrade from Rails 3 params.permit! to pass mass assignment
Like this you have a normal controller for manage your User model likes other application controllers.
in controller/users_controller.rb
def update
#user = User.find(params[:id])
respond_to do |format|
if #user.update_attributes(user_params)
format.html { redirect_to #user, notice: 'User was successfully created.' }
else
format.html { redirect_to #user, notice: 'Errors.' }
end
end
end
private
def user_params
params.permit!
end
I've just change my database from sqlite3 to postgresql in my Ruby on rails.
Every things worked before but now I have a "wrong number of arguments (2 for 1)" when I submit the form. I don't understand why !
Here my code :
my photo_controller file :
class PhotosController < ApplicationController
before_action :set_photo, only: [:show, :edit, :update, :destroy]
# GET /photos
# GET /photos.json
def index
#photos = Photo.all
end
# GET /photos/1
# GET /photos/1.json
def show
end
# GET /photos/new
def new
#photo = Photo.new
end
# GET /photos/1/edit
def edit
end
# POST /photos
# POST /photos.json
def create
#photo = Photo.new(photo_params)
respond_to do |format|
if #photo.save
format.html { redirect_to #photo, notice: 'Photo was successfully created.' }
format.json { render action: 'show', status: :created, location: #photo }
else
format.html { render action: 'new' }
format.json { render json: #photo.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /photos/1
# PATCH/PUT /photos/1.json
def update
respond_to do |format|
if #photo.update(photo_params)
format.html { redirect_to #photo, notice: 'Photo was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #photo.errors, status: :unprocessable_entity }
end
end
end
# DELETE /photos/1
# DELETE /photos/1.json
def destroy
#photo.destroy
respond_to do |format|
format.html { redirect_to photos_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_photo
#photo = Photo.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def photo_params
params.require(:photo).permit(:image)
end
end
my photo.rb file :
class Photo < ActiveRecord::Base
has_attached_file :image
end
my new.html.erb file ( here is the form and after I chose the image and submit it, I have the error ) :
<h1>New photo</h1>
<%= form_for #photo, :html => { :multipart => true } do |f| %>
<div class="field">
<%= f.file_field :image %>
</div>
<div class="action">
<%= f.submit %>
</div>
<% end %>
my show.html.erb file :
<h1> Je viens de faire un upload ! </h1>
<% if #photo.image? %>
<!-- Load Feather code -->
<script type="text/javascript" src="http://feather.aviary.com/js/feather.js"></script>
<!-- Instantiate Feather -->
<script type='text/javascript'>
var featherEditor = new Aviary.Feather({
apiKey: ' f20374413e3ff5a8',
apiVersion: 3,
theme: 'light', // Check out our new 'light' and 'dark' themes!
tools: 'all',
appendTo: '',
onSave: function(imageID, newURL) {
var img = document.getElementById(imageID);
img.src = newURL;
},
onError: function(errorObj) {
alert(errorObj.message);
}
});
function launchEditor(id, src) {
featherEditor.launch({
image: id,
url: src
});
return false;
}
</script>
<div id='injection_site'></div>
<img id='image1' src='<%= #photo.image.url %>'/>
<!-- Add an edit button, passing the HTML id of the image and the public URL of the image -->
<p><input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit photo' onclick="return launchEditor('image1', '<%= #photo.image.url %>');" /></p>
<% end %>
Backtrace:
Application trace :
app/controllers/photos_controller.rb:27:in `create'
Full trace :
activesupport (4.0.0) lib/active_support/callbacks.rb:78:in `run_callbacks'
paperclip (3.0.4) lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
paperclip (3.0.4) lib/paperclip/attachment.rb:382:in `post_process'
paperclip (3.0.4) lib/paperclip/attachment.rb:106:in `assign'
paperclip (3.0.4) lib/paperclip.rb:194:in `block in has_attached_file'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `public_send'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `_assign_attribute'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:29:in `block in assign_attributes'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `each'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `assign_attributes'
activerecord (4.0.0) lib/active_record/core.rb:192:in `initialize'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
app/controllers/photos_controller.rb:27:in `create'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:413:in `_run__921501253494556441__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__2330035833412540959__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Please help me :)
Looks like you're seeing this error and you should just upgrade Paperclip to the latest version, 3.5.2.
You're running a pretty old paperclip anyway.
Just pulling out the essential pieces from above:
Error:
wrong number of arguments (2 for 1)
Source:
Controller:
1: class PhotosController < ApplicationController
...
24: # POST /photos
25: # POST /photos.json
26: def create
27: #photo = Photo.new(photo_params)
Model:
class Photo < ActiveRecord::Base
has_attached_file :image
end
View:
<%= form_for #photo, :html => { :multipart => true } do |f| %>
<div class="field">
<%= f.file_field :image %>
</div>
<div class="action">
<%= f.submit %>
</div>
<% end %>
Stacktrace:
Application trace :
app/controllers/photos_controller.rb:27:in `create'
Full trace :
activesupport (4.0.0) lib/active_support/callbacks.rb:78:in `run_callbacks'
paperclip (3.0.4) lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
paperclip (3.0.4) lib/paperclip/attachment.rb:382:in `post_process'
paperclip (3.0.4) lib/paperclip/attachment.rb:106:in `assign'
paperclip (3.0.4) lib/paperclip.rb:194:in `block in has_attached_file'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `public_send'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `_assign_attribute'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:29:in `block in assign_attributes'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `each'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `assign_attributes'
activerecord (4.0.0) lib/active_record/core.rb:192:in `initialize'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
app/controllers/photos_controller.rb:27:in `create'
After trying to install the "Restful-Authentication"-plugin on my Ruby on Rails site, I've been meeting some problems.
I'm still new to Ruby on Rails, and programming in general, so I might probably have forgotten something, maybe.
I'm running Ruby 1.9.3p125, and Rails 3.2.1
When browsing to the signup page, I get this error message:
uninitialized constant User::Authentication
Then, if I refresh the page, I receive this other error message:
undefined method `key?' for nil:NilClass
Full Trace:
actionpack (3.2.1) lib/action_controller/metal/hide_actions.rb:36:in `visible_action?'
actionpack (3.2.1) lib/action_controller/metal/hide_actions.rb:18:in `method_for_action'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:14:in `method_for_action'
actionpack (3.2.1) lib/action_controller/metal/compatibility.rb:61:in `method_for_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:115:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30: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.1) lib/action_dispatch/routing/route_set.rb:589:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__960052277__call__392212310__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
app/controllers/users_controller.rb
class UsersController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# render new.rhtml
def new
#user = User.new
end
def create
logout_keeping_session!
#user = User.new(params[:user])
success = #user && #user.save
if success && #user.errors.empty?
redirect_back_or_default('/', :notice => "Thanks for signing up! We're sending you an email with your activation code.")
else
flash.now[:error] = "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)."
render :action => 'new'
end
end
def activate
logout_keeping_session!
user = User.find_by_activation_code(params[:activation_code]) unless params[:activation_code].blank?
case
when (!params[:activation_code].blank?) && user && !user.active?
user.activate!
redirect_to '/login', :notice => "Signup complete! Please sign in to continue."
when params[:activation_code].blank?
redirect_back_or_default('/', :flash => { :error => "The activation code was missing. Please follow the URL from your email." })
else
redirect_back_or_default('/', :flash => { :error => "We couldn't find a user with that activation code -- check your email? Or maybe you've already activated -- try signing in." })
end
end
def forgot
if request.post?
user = User.find_by_email(params[:user][:email])
respond_to do |format|
if user
user.create_reset_code
flash[:notice] = "Reset code sent to #{user.email}"
format.html { redirect_to login_path }
format.xml { render :xml => user.email, :status => :created }
else
flash[:error] = "#{params[:user][:email]} does not exist in system"
format.html { redirect_to login_path }
format.xml { render :xml => user.email, :status => :unprocessable_entity }
end
end
end
end
def reset
#user = User.find_by_reset_code(params[:reset_code]) unless params[:reset_code].nil?
if request.post?
if #user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation])
self.current_user = #user
#user.delete_reset_code
flash[:notice] = "Password reset successfully for #{#user.email}"
redirect_to root_url
else
render :action => :reset
end
end
end
end
app/views/users/new.html.erb
<h1>Sign up as a new user</h1>
<% #user.password = #user.password_confirmation = nil %>
<%= error_messages_for :user %>
<%= form_for :user, :url => users_path do |f| -%>
<p><%= label_tag 'login' %><br/>
<%= f.text_field :login %></p>
<p><%= label_tag 'email' %><br/>
<%= f.text_field :email %></p>
<p><%= label_tag 'password' %><br/>
<%= f.password_field :password %></p>
<p><%= label_tag 'password_confirmation', 'Confirm Password' %><br/>
<%= f.password_field :password_confirmation %></p>
<p><%= submit_tag 'Sign up' %></p>
<% end -%>
config/routes.rb
Blog::Application.routes.draw do
resources :users
resource :session, :only => [:new, :create, :destroy]
match 'signup' => 'users#new', :as => :signup
match 'register' => 'users#create', :as => :register
match 'login' => 'sessions#new', :as => :login
match 'logout' => 'sessions#destroy', :as => :logout
match 'forgot', :controller => 'users', :action => 'forgot'
match 'reset/:reset_code', :controller => 'users', :action => 'reset'
match '/activate/:activation_code' => 'users#activate', :as => :activate, :activation_code => nil
resources :posts do
resources :comments
end
(...)
If you need more files, then just let me know.
Thanks!