Rails Problems, Missing Template - ruby-on-rails

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

Related

Active Admin resources missing template after upgrade to v1.1.0

ActiveAdmin.register Document do
controller do
def create
create!
end
end
end
This was working fine in ActiveAdmin 0.6.6 however after upgrading to v1.1.0 it is unable to find the create template and ActionView::MissingTemplate is thrown:
Missing template documents/create, active_admin/resource/create, active_admin/base/create, inherited_resources/base/create, application/create with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :haml]}. Searched in:
* "/Users/ent/Desktop/Apps/vent/app/views"
* "/Users/ent/.rvm/gems/ruby-2.5.5/gems/activeadmin-1.1.0/app/views"
* "/Users/ent/.rvm/gems/ruby-2.5.5/gems/kaminari-core-1.1.1/app/views"
* "/Users/ent/.rvm/gems/ruby-2.5.5/gems/devise_cas_authenticatable-1.10.4/app/views"
* "/Users/ent/.rvm/gems/ruby-2.5.5/gems/devise-4.6.2/app/views"
Is there anything that has changed since the upgrade that I am missing?
I have tried the following versions of active admin: 1.0.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.4.0, 1.4.1, 1.4.2, 1.4.3 however they all have the same error. Downgrading back to 0.6.6 seems to resolve the issue.
I think it's because create does not typically have it's own view.
To fix it, you can use this construct and instruct controller action what to do on success / failure of the create action. In this example, on success we will redirect to the resource detail, on failure we will render the new view (as most likely the validation of the resource failed and user needs update and resubmit the form):
controller do
def create
super do |success, failure|
success.html { redirect_to your_resource_path(resource), notice: "#{resource.name} has been created." }
failure.html { render :new }
end
end
end

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

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 4 "Template is missing" error with jasper-rails gem

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

why won't rails find rabl templates?

working on an api, using the rails-api and rabl gems, basing understanding off railscasts 348 and 322
currently getting
Missing template activities/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :rabl]}. Searched in:
* "/Users/jd/Dropbox/honeybadgerconsulting/activitiesapi/app/views"
but best I can tell, my setup mirrors the screencasts, is there a detail i'm overlooking ?
controller is
class ActivitiesController < ApplicationController
include ActionController::ImplicitRender
def index
#activities = Activity.all
end
end
and path to rabl template is /app/views/activities/index.json.rabl
context of json.rabl
collection #activities
attributes :title, :vendor, :date, :start_time, :price
Your request URL has to end in ".json", rails thinks it's an HTML request.

Resources