I have added rails_admin in my application. Now I need to add an additional feature, that is send email to all users from the rails application. How can I add a new view with in rails_admin. Currently I have added a new static menu in rails_admin.rb
config.navigation_static_links = {
'Compose' => '/admin/email'
}
But it is opened in a new tab as a seperate view with no side bar, footer, header etc..
I want to add this feature like dashboard. Please give some useful hints for my issue. Thanks in advance
probably you will need to create what RailsAdmin define as Action for your Admin role and make sure you manage correctly the admin authentication with Devise
You can implement a method that sends email with ActionMailer, I am quoting the solution from Hitham S.AlQadheeb from the following post. Go check his post for more info.
For each call to the mailer method one email is sent in scheduled worker
def calling_method
#users.each do |user|
send_digest(user.email, user.name)
end
end
in user mailer
def send_digest(user_email, user_name)
mail(to: user_email, subject: user_name)
end
You need to create a custom action
https://github.com/sferik/rails_admin/wiki/Custom-action
Based on the dashboard
https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/actions/dashboard.rb
And if you want a link to it visible at all times, you will need to override the existing navigation partial on your project.
https://github.com/sferik/rails_admin/blob/master/app/views/layouts/rails_admin/_navigation.html.haml
Related
I need to modify the emails which go to the customers in the spree app.
At the moment a very ordinary form goes to the customer email.
I am unable to find the code where I can modify that email and add custom template.
Anyone having worked on this point earlier?
The mail templates are in core/app/mailers/spree and the mail that goes out after orders should be core/app/mailers/spree/order_mailer.rb.
In app/mailers/spree you need to create a file called order_mailer_decorator.rb. In this file you add:
Spree::OrderMailer.class_eval do
def confirm_email(order, resend = false)
your code
end
end
In views/spree/order_mailer in a file confirm_email.html.erb you need to write your code.
I have made this simple test app that have 2 different authentication model
- User
- Admin
https://github.com/axilaris/admin_user_devise_articles
I want to have different view layouts for User and Admin for devise. How can I customize this.
For example:
localhost:3000/users/sign_in
should be different than
localhost:3000/admins/sign_in
Please feel free to modify my github repo to have this different sign_in/sign_up views. Thanks.
in application controoler I added a method called after_sign_in_path_for which checks role and redirect to required view
here is a method
def after_sign_in_path_for(resource)
if resource.has_role? :admin
users_path
else
root_path
end
end
hope this will help you
Basically Deep has the answer, its in here:
github.com/plataformatec/devise#configuring-views
do this:
rails generate devise:views users
set:
config.scoped_views = true inside the config/initializers/devise.rb file.
updating the git repo to reflect this feature. thanks #Deep
Im using RoR 3.2.3 and Devise and Active Admin is working great.
However, there is something I am not getting.
In my app, users cannot register themselves, only an Admin can register other users.
This is all working, the Admin goes into the Active Admin panel->Users->New and fills the username and email and clicks "Create".
In order to give the customer the option of clreating his new password I'm using in mt AA user model:
after_create { |user| user.send_reset_password_instructions }
def password_required?
new_record? ? false : super
end
However, I don't want the email to send the text that devise uses, but rather a welcoming text and not something like "A link to change your password has been requested..." as there was no password to begin with.
In short, I want to use the send_reset_password_instructionsdevise method without using it's devise/mailer/reset_password_instructions view for when a new user is created.
However if the user forgets his password then he clicks the "Forgot Password" link and an email is to be sent with that default text already provided by Devise.
Any tips on how to make this work?
Thanks in advance,
Regards
Its very simple actually, set config.scoped_views = true in config/initializers/devise.rb
Then run
rails g devise:views users
this will generate all the views files devise uses, you can make changes to the
app/views/users/mailer/reset_password_instructions.html.erb file to what you need or any other file you wish to change.
I have a rails application that I am trying to integrate devise_invitable into. So, of course the authentication system is Devise. Devise doesn't do the signups rather, it is handled by a CRUD controller so only an admin can use it to sign up.
In my code at the top I have:
class UsersController<ApplicationController
I'm not sure if it has to be changed to
class UsersController<Devise::InvitationsController
because, when I try to do it my route says that /users is not a path.
The CRUD controller is simple with new looking like this:
def new
#user = User.new
end
I also don't think it is the view as I added a debug to to the log file when it gets into it,and it does. Plus, this was working fine before I tried to add devise_invitable.
Any ideas on to why it would not display the form? The console is also not showing any errors.
I needed to add an equals sign in front of form_for so instead of <% form_for(user)%> use <%=form_for(user)%>
I know how to change the password using devise but I don't know how to create a link to an action for the current admin user. For example adding a link under the email.
Change password
and that would send to an action calling:
send_reset_password_instructions
I can't really find any good documentation for ActiveAdmin, the official site expose some examples but nothing there is really explained. Its unclear where and how things works.
You'll want to look at ActiveAdmin's documentation on custom controller actions. I've accomplished this by creating a "member_action" (a custom controller action which acts upon a single record), and adding an "action_item" to perform it (those are the buttons which appear in the top right when viewing a record). Here's how I make it work:
# in app/admin/admin_users.rb
action_item do
# Link to perform the member_action, "reset_password" defined below
link_to("Reset Password", reset_password_admin_admin_user_path(admin_user))
end
member_action :reset_password do
# Find the user in question
admin_user = AdminUser.find(params[:id])
# Call the method (from Devise) which sends them a password reset email
admin_user.send_reset_password_instructions
# Redirect back to the user's page with a confirmation
redirect_to(admin_admin_user_path(admin_user),
notice: "Password reset email sent to #{admin_user.email}")
end