User model has a function
def self.createadmin(
User.create(:email => "abc#gmail.com", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1')
end
In rake db:seed, I have to call User.createadmin
However, this fails
ActionView::Template::Error: ActionView::Template::Error
from /Users/bever/Projects/tr/app/views/devise/mailer/confirmation_instructions.html.erb:3:in `_app_views_devise_mailer_confirmation_instructions_html_erb___1974818942364630283_2154906860'
Then I changed the code in createadmin
begin
User.create(:email => "abc#gmail.com", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1')
rescue => e
User.create(:email => "abc#gmail.com", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1')
end
It works! Any clue why this is happening?
Have you tried seeding from the db/seeds.rb file instead of the model? When you try to do it on the model, devise is probably trying to send the conformation mail.
You should create your admin user on the seeds.rb file like this
User.create(:email => "abc#gmail.com", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1')
Remember that if you are using confirmable module of devise you should add this field to the query.
:confirmed_at => Time.now
Maybe you should add the confirmation tokens and other fields useful to administrate your admin account via your rails app and not on the console.
PD: Probably if you post more of the error shown and maybe the line in the view I can help you more.
Greetings
Related
Hello i know this is common problem but i cant let it work.. I need account activation from email link.. url looks like http://domain.tld/activation/name#domain.tld/d4sa89dsa98 and i want access that parameters from controller :-)
routes.rb
match "activation/:email/:activation_key" => "frontend#activation", :via => :get
frontend_controller.rb
def activation
#user = User.find(:conditions => {:email => params[:email], activation_key => params[:activation_key]})
render "activation"
end
and im getting error
No route matches [GET] "/activation/name#email.tld/a46d4sa8dsa68d"
my activation.html.erb
<% if #user %>
Activation successful.
<% else %>
Activation key is invalid.
<% end %>
EDIT: ---------------------------------------------------------------------------------------------------------------------------
I replaced :email parameter with :id parameter because it look nicer, im not sure if
Array.new(32){Random.new.rand(36).to_s(36)}.join is unique string but that does not matter now.
route
match "activation/:id/:activation_key" => "frontend#activation", :via => :get
rake routes
GET /activation/:id/:activation_key(.:format) frontend#activation
frontend controller
def activation
#user = User.find(:conditions => {:id => params[:id], :activation_key => params[:activation_key]})
render "activation"
end
error
Couldn't find User without an ID
but this WORKS so the problem is in the condition
#user = User.find(params[:id])
SOLUTION
#user = User.find(:first, :conditions => {:id => params[:id], :activation_key => params[:activation_key]})
Have you tried adding a constraints: { email: /[^\/]+/ } to your match argument? Possibly the . gets eaten up by overly greedy regex.
I first installed devise and altered it so I can login with username instead of email.
After that I entered the Activeadmin gem into my gem file.
After that I did a bundle install and rake active_admin:install.
But after trying to log into the backend /admin/login I see this error message :
undefined method `username' for #<AdminUser:0x00000004bb2e58>
On this code :
Extracted source (around line #7):
4: <% scope = Devise::Mapping.find_scope!(resource_name) %>
5: <%= active_admin_form_for(resource, :as => resource_name, :url => send(:"#{scope}_session_path"), :html => { :id => "session_new" }) do |f|
6: f.inputs do
7: resource.class.authentication_keys.each { |key| f.input key, :input_html => {:autofocus => true}}
8: f.input :password
9: f.input :remember_me, :label => t('active_admin.devise.login.remember_me'), :as => :boolean, :if => false #devise_mapping.rememberable? }
10: end
Anyone a idea how to solve this ?
If you need more info just ask.
Roelof
edit : I thought I could solve this by doing this: http://blog.blazingcloud.net/2012/07/29/activeadmin-with-existing-devise-authentication/
But now all the login are failed ( 401) where they without activeadmin they were successfull
I was having the same error and I solved it adding this to my AdminUser model
def login=(login)
#login = login
end
def login
#login || self.email
end
def self.find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
login = conditions.delete(:login)
where(conditions).where(["lower(email) = :value", { :value => login.strip.downcase }]).first
end
I would like to create a link to approve a users signup,
1) First solution<%= link_to "Approve", edit_user_registration_path(:id => user.id, :approved => true), :method => :put %>
However it drops back No route matches [PUT] "/users/edit"
2) Also I was thinking about an extra action that will respond to a specific route and update the user signup, say match '/users/approve_user', :controller => 'users', :action => 'approve_user', :collection => { :my_action => :put}
and in the view:
%- link_to "Approve", users_approve_user_path(:id => user.id), :method => :put
However, it gives back that Couldn't find User with ID=approve_user
Any help will be appreciated
I think you should use custom routing with devise
This is direct from devise documentation (https://github.com/plataformatec/devise), configuring routes
devise_scope :user do
get "sign_in", :to => "devise/sessions#new"
end
so in your case try something like
devise_scope :user do
post "Approve", :to => "users/approve_user"
end
and please note, by default device users controller comes under the name space 'devise'.
We want to send an autogenerated E-Mail with an full path to the profile. How do we this
<%=link_to('Link', :controller => 'mycontroller', :action => 'show', :id => #mycontroller.id )%>
The link_to command only builds the link in the mail like this
mycontroller/show/id
we need an link like this structure
http://www.server.tld/mycontroller/show/id
Can everyone help us please?
you can pass :only_path => false
<%= link_to('Link', :controller => 'mycontroller', :action => 'show', :id => #mycontroller.id, :only_path => false ) %>
<%= will_paginate #semails, :renderer => 'RemoteLinkRenderer' , :remote => {
:loading => 'loadingPanel.show()',:complete => 'loadingPanel.hide()'} %>
in rails2
how to convert this to rails3
This is the routes using for rails 2 for semails
map.resources :users,
:collection => {:uapload_avatars => :post, :aselect_friend => :get, :alist_friend => :get, :aist_moderator => :get},
:member => {:anew_avatars => :get, :acreate_avatar => :post
} do |user|
user.resources :semails, :collection => { :sort => :get, :asave_draft => :post }
end
how to convert this routes in rails 3 ?
I'm facing this error
will clicking the pagination link it just redirecting to the home page is that routes issue or will paginate issue in rails 3
please help me to solve this issue
I'm not 100% about the spelling but the new routes for rails would approximate something like this:
resources :user do
collection do
post "uapload_avatars"
get "aselect_friend"
end
resources :semails do
collection do
get "sort"
post "asave_draft"
end
end
end
http://guides.rubyonrails.org/routing.html