ActionView::MissingTemplate despite redirect and render nothing - ruby-on-rails

I am having a problem with a Ruby on Rails app running on Heroku. The method set_default_activities of activities controller ends on
redirect_to root_path
but it appears to be looking for a view template called "activities/set_default_activities":
2016-06-23T04:15:39.021209 #3] FATAL -- :
2016-06-23T04:15:39.021744+00:00 app[web.1]: ActionView::MissingTemplate (Missing template activities/set_default_activities, application/set_default_activities with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}.
I have read the previous posts on this error and they appeared to suggest adding the line
render nothing: true
I have done this on the second-to-last line but the problem persists. What should I try next?

In your activities controller, modify the redirect line to:
redirect_to root_path and return

Related

Rails error finding actionmailer template despite email sending correctly

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

Rspec missing template error - html+phone.slim (variants) - how to?

I have a view with the following format:
show_map.html+phone.slim
I am testing my controller, expecting my test to render that template , does anyone know the proper syntax for rendering a view with variant ?
This is what I am trying:
describe "show_map action" do
it "renders show map view" do
get :show_map, {:id=>#job.id,:format=>:html,:variants=>:phone}
expect(response).to render_template('show_map')
end
also tried
get :show_map, {:id=>#job.id,:format=>'html.phone'}
Either way, I get a missing template error:
JobsController show_map action renders show map view
Failure/Error: get :show_map, {:id=>#job.id,:format=>:html,:variants=>:phone}
ActionView::MissingTemplate:
Missing template jobs/show_map, application/show_map with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :slim]}
Anyone know how to do this?

Rails Problems, Missing Template

I'm a newbie to Rails and beginning my crud application. I've created the form perfectly fine but when I click the submit button this error appears, could someone please explain the error and how I would go about resolving this error
Missing template posts/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/Users/shannon/beginner/app/views"
My controller:
class PostsController < ApplicationController
def new
end
def create
render plain: params[:posts].inspect
end
May be you are using Rails version prior 4.1, render plain is added in Rails 4.1. So Rails is ignoring plain option and looking for template posts/create.
in Rails 4.1 you can do:
render plain: params[:posts].inspect
in Rails 4.0 you need to do:
render text: params[:posts].inspect

where to store a jbuilder template?

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.

Rails: render value without view

i've a problem
i'm trying to make an action method like this
def webm
#url = Video.find(params[:id]).avatar.url(:webm_sd)
end
and i just want to return the #url value without using view .. it will return string url i need it to be rendered where ever the method get called
it gives me error
Missing template api/v1/videos/webm, application/webm with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
and even if i add some views in videos folder it still gives me the same error!
what should i do?
You can use proper renderer
render json: #url
or to render just string
render text: #url

Resources