I am using ruby on rails version 4.2.4 and devise 4.0.0
I have problems with reset password and I am trying to override and reset to the new password by overriding devise myself. Now that I have the code to change password, i need to complete the "update" function.
Below is my code to override Devise::PasswordsController
in route.rb:
devise_for :users, controllers: { passwords: 'users/passwords' }
in controller/users/password_controller.rb
class Users::PasswordsController < Devise::PasswordsController
def create
super
puts "create PasswordsController"
end
def new
super
puts "new PasswordsController"
end
def update
reset_password_token_hash = Devise.token_generator.digest(self, :reset_password_token, resource_params['reset_password_token'])
user = User.find_by_reset_password_token(reset_password_token_hash)
user.update(password: resource_params['password'])
#xxxx respond_with resource, needs to do something like this ??
end
def edit
super
puts "edit PasswordsController"
end
end
it manage to change password but has problem with the page:
Completed 500 Internal Server Error in 176ms (ActiveRecord: 13.0ms)
ActionView::MissingTemplate - Missing template users/passwords/update, users/passwords/update, devise/passwords/update, devise/update, application/update with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :slim, :jbuilder]}. Searched in:
* "/Users/megasap/Documents/project/harta.org/harta.org-backend/app/views"
* "/Library/Ruby/Gems/2.3.0/gems/ckeditor-4.2.2/app/views"
* "/Library/Ruby/Gems/2.3.0/gems/grape-swagger-rails-0.2.0/app/views"
* "/Library/Ruby/Gems/2.3.0/gems/devise-4.0.0/app/views"
Can someone let me know how to complete the "update" method for Users::PasswordsController
Related
I'm building a simple login screen. I'd like to return an :internal_server_error to my client if there isn't a matching user or if the password is incorrect. However, I'm getting the following missing template error:
ActionView::MissingTemplate (Missing template login/index,
application/index with {:locale=>[:en], :formats=>[:json],
:variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby,
:coffee, :jbuilder]}. Searched in: *
"C:/Shelf/myGroceryList/app/views"
What has me confused is that I have an index.html.erb template in views/login. Thoughts?
Route:
post '/login', to: 'login#show'
Controller(login_controller.rb):
class LoginController < ApplicationController
protect_from_forgery with: :null_session
def index
end
def show
username = params.values.last["email"]
password = params.values.last["password"]
loginType = params.values.last["loginType"]
if loginType == "Login"
login(username, password)
else
createNewUser(username, password)
end
end
def login(username, password)
begin
user = User.find_by(username: username)
raise(StandardError) if user.password != password
rescue
render 'index', :status => :internal_server_error
end
end
def createNewUser(username, password)
User.new(username: username, password: password)
end
end
View(index.html.erb):
<body><%= javascript_pack_tag 'login' %></body>
ActionView::MissingTemplate (Missing template login/index,
application/index with {:locale=>[:en], :formats=>[:json],
:variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby,
:coffee, :jbuilder]}. Searched in: *
"C:/Shelf/myGroceryList/app/views"
The error says it can't find the file with the name index and with the format json. As are you having an API, probably the request/response would be in the format json not html. That said you need to create a index.json.erb inside app/views/login to resolve the error.
I am new to using mailer and read a few tutorials but can't for the life of me work out why this this error is appearing
Missing template layouts/mailer with {:locale=>[:en], :formats=>[:text], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :haml]}. Searched in:
* "/Users/paulmcguane/RoR/barista/app/views"
* "/Users/paulmcguane/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/devise-3.5.6/app/views"
new_record_notification.text.erb
Hi,
A new record has been added: <%= #record.name %>
Thanks
model_mailer.rb
class ModelMailer < ApplicationMailer
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.model_mailer.new_record_notification.subject
#
def new_record_notification(record)
#record = record
mail(to: 'email#address') do |format|
format.text
end
end
end
Most likely you use layout 'mailer' in your ApplicationMailer class. Use existing layout or don't use layout at all.
I have a rails app running on passenger with a mailer. I have it so the page following the action shows the email content but I get this error:
Missing template rfis/mail, application/mail with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :slim, :jbuilder]}. Searched in: * "/var/www/rqm3/app/views" * "/usr/local/rvm/gems/ruby-2.1.5/gems/devise-3.5.1/app/views" * "/usr/local/rvm/gems/ruby-2.1.5/gems/twitter-bootstrap-rails-3.2.0/app/views"
despite this, the email does correctly load the template when being sent. It's only showing it in a view that causes issues.
rfis_controller.rb:
def mail
#mail_message = RfiMailer.send_rfi(current_user, #rfi).deliver
end
rfi_mailer.rb:
class RfiMailer < ApplicationMailer
default from:"testemail#mail.com"
def send_rfi(user, rfi)
mail(to:"other#test.com")
end
end
send_rfi.html.erb:
test
Issue is due to you are not redirecting anything inside your method "mail" define inside controller
def mail
#mail_message = RfiMailer.send_rfi(current_user, #rfi).deliver
redirect_to #user, notice: "Message sent successfully ."
end
you can also define render nothing
I'm attempting to use a jbuilder template.
Given the controller,
class Api::ReviewsController < ApplicationController
before_filter :authenticate_user!
respond_to :json
def create
#review_request = ReviewRequest.new(review_request_params.merge(user_id: current_user.id))
if #review_request.save
render 'review_requests/review'
else
head :forbidden
end
end
end
and I have the jbuilder template stored at app/views/review_requests/review.json.jbuilder
json.review_request do
json.(#review_request, :title,)
end
I'm getting a template note found error.
ActionView::MissingTemplate (Missing template review_requests/review with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/jd/Dropbox/application-code/antipattern/app/views"
* "/Users/jd/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/devise-3.4.1/app/views"
* "/Users/jd/Dropbox/application-code/antipattern"
* "/"
):
app/controllers/api/reviews_controller.rb:8:in `create'
Any thoughts on either where the correct place to store this template is or why rails isn't finding the template i'm using (if the storage location happens to be ok)?
jbuilder needs a json type web request, an html request to a rails server will cause the jbuilder template to not be rendered.
I have installed the jasper-rails 1.0.3 and followed the instructions as per https://github.com/fortesinformatica/jasper-rails. My java installation is fine.
Here is my controller code:
class ReportsController < ApplicationController
respond_to :html, :xml, :pdf
def index
#council_report = CouncilReport.find(params[:council_report_id])
end
def proposed_works_summary
#council_report = CouncilReport.find(params[:council_report_id])
#proposed_works_summary = proposed_works_summary_data(#council_report.id)
respond_with #proposed_works_summary
end
end
My routes.rb:
...
resources :reports, only: [:index] do
member do
get 'proposed_works_summary'
end
end
...
Here is the error in the browser:
Template is missing
Missing template reports/proposed_works_summary, application/proposed_works_summary with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "d:/Users/Michael/Documents/Aptana Workspace/cam/app/views"
Now I obviously have a proposed_works_summary.jrxml iReport file and I have set the queryString as follows:
<queryString language="XPath">
<![CDATA[/reports/proposed_works_summary]]>
</queryString>
I have examined the demo https://github.com/fortesinformatica/jasper-rails-demo in detail and can't see what I am missing. A little help please?
I had the same problem, I resolved it doing a little update to jasper-rails because it does not supported on Rails 4.2, if you like can prove it jasper-rails