Rails trying to find users folder with jbuilder files, which exist, but can't
Application
Missing template users/index, application/index with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :slim, :coffee, :jbuilder]}. Searched in:
* "/home/bjorn/Documents/poller/app/views"
* "/usr/lib/ruby/gems/2.3.0/gems/devise_token_auth-0.1.37/app/views"
* "/usr/lib/ruby/gems/2.3.0/gems/devise-4.0.3/app/views"
full error stack
# controllers/users_controller.rb
class UsersController < ApplicationController
def index
#users = User.all
end
def show
#user = User.find(params[:id])
end
end
# routes.rb
resources :users, only: [ :index, :show ]
I cloned your repo and I don't get this exception at /api/users.
However you need to rename your layout file application.slim to application.html.slim. Otherwise jbuilder will render the layout too.
Related
I am overriding devise session controler and while trying to set specific format Rails says there's no partial while it's not true
while I am trying to insert it inside respond_to
class SessionsController < Devise::SessionsController
def new
self.resource = resource_class.new(sign_in_params)
clean_up_passwords(resource)
yield resource if block_given?
respond_to do |format|
format.html
format.json {render(json: { sign_in: render_to_string(partial: 'static_pages/home')})}
end
end
The error is:
Missing partial static_pages/_home with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder]}. Searched in: * "D:/project_traveldiary/app/views" * "D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/devise-4.6.2/app/views"
Looks like it searches for json partial, so try to explicitly specify the format of the partial:
render_to_string(partial: 'static_pages/home', formats: :html)
After setup a simple API and try to login with a simple session controller
Session Controller
def create
user = User.find_by(email: [:email])
if user && user.authenticate([:password])
render json: {token: user.access_token}, status: 200
else
render text: "Email and password combination are invalid", status: 422
end
end
in the logs show
ActionView::MissingTemplate (Missing template sessions/create,
application/create with {:locale=>[:en], :formats=>[:json],
:variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby,
:jbuilder]}. Searched in: * "/home/daniel/ranks/app/views" ):
after googling around seems a issue with jbuilder and the workaround that some proposed was to: in the application controller
include ActionView::Rendering
def render_to_body(options)
_render_to_body_with_renderer(options) || super
end
but the problem persist so someone has any idea how to solve this issue with rails 5.1 and jbuilder 2.7.0?
Missing template events/index, application/index with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml]}. Searched in: * "c:/Put/Team/project/app/views" * "c:/Put/Team/project/vendor/bundle/ruby/2.0.0/gems/browserlog-0.0.2/app/views" * "c:/Put/Team/project/vendor/bundle/ruby/2.0.0/gems/devise-3.4.1/app/views"
Here is the error I encounter when I'm trying to create a pdf from the ruby application I have made. This error occurs when I put .pdf on the end of my URL.
This is the code I've implemented in my app controller file
def show
#event = current_user.events.find(params[:id])
respond_to do |format|
format.html
format.pdf do
pdf.text = Prawn::Document.new
pdf.text "Hello World"
send_data pdf.render
end
end
end
It wants to render a template in your views, so my guess it's not recognizing your PDF render statement. It is odd that the pointer is to events/index while you're saying the source is the show method.
Try referring to this StackOverflow thread:
How to render format in pdf in rails
Make sure you name your view to "show.pdf".
I have commendations/_create.html.erb which includes in a form -
<%= form_for(current_user.commendations.new(...), remote: true) do |f| %>
<%=...
and in commendations_controller.rb
def create
...
respond_to do |format|
format.html { redirect_to :back }
format.js
end
end
but I'm getting the following error in the server log -
Completed 500 Internal Server Error in 7ms
ActionView::MissingTemplate (Missing template commendations/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/dan/Documents/ROR/fic/app/views"
* "/Users/dan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/devise-3.4.1/app/views"):
app/controllers/commendations_controller.rb:9:in `create'
I can't see where I'm going wrong - the remote: true should trigger format.js which in turn should reload the partial, no?
In routes.rb I have
resources :commendations, only: [:create]
You need a file called create.js within app/views/commendations/
And in create.js do:
$("#your_div").html( "<%= j render( :partial => 'commendations/your_partial') %>" );
Trying to get User model to print to JSON, tried making a file with a json.rabl extension as follows:
file.json.rabl
object #users
attributes :id, :name
When I try to view this, I get the following error message:
Missing template users/autocomplete, application/autocomplete with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee, :rabl, :rb]}.
However, if I rename the file to file.rabl, it renders the JSON, but in an HTML page instead. How do I get it to print a pure JSON file?
Here is my controller code for the file view:
def file
#users = User.all
respond_to do |format|
format.html
format.json
end
Just had to add .json to the URL.