I'm trying to render my pagination links inside an ajax request with kaminari and im getting a server error. I'm using the render_to_string method to render the pagination links to a string then parse it via json. I'm using rails 3.1.0.
ActionView::Template::Error (Missing partial kaminari/paginator with {:handlers=>[:erb, :builder, :haml], :formats=>[:json], :locale=>[:en, :en]}. Searched in:
Basically it's looking for the partials in all my load paths and can't seem to find the files, and they're there for sure.
Has anyone experienced similar behavior and know of a possible reason?
I just ran into this as well. I was able to work around it by moving render_to_string into a respond_to block -
respond_to do |format|
format.js do
foo = render_to_string(:partial => 'some_kaminari_view').to_json
render :js => "$('#foo').html(#{foo})"
end
end
See here: http://whowish-programming.blogspot.com/2011/07/stupid-rails3-with-missing-template-and.html
Just append .html to your view name.
Related
I am working on a Rails app. I have a form where the user can submit some files. The form is doing an AJAX call (it has the remote: true attribute). Whenever I want to send a file using the "f.file_field :banner" helper, the server responds with
Missing template posts/update with {:locale=>[:fr], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :slim]}. Searched in: ...
I have tried to add a respond_to block into my controller but then the server throws an ActionController::UnknownFormat.
Why is it not rendering my JS template ONLY when I submit a file? The form works fine when I just submit text.
Thank you for you help!
EDIT:
My form:
= bootstrap_form_for #section, remote: true do |f|
= f.file_field :banner
...
My controller:
# PATCH/PUT /sections/1
def update
#section.update(section_params)
manage_photos
render "posts/update"
end
Solution:
Using the remotipart gem !
Your problem is specifically the line in your controller:
render "posts/update"
in your views directory, do you have a file posts/update.html.erb or the like. That is what it is trying to render. It can't find the file. What are you trying to do with that line?
UPDATE:
Try doing this:
render 'posts/update', formats: [:js]
I'm using Rails 3.2.21 with JBuilder.
I have an example where I'm using an a JBuilder partial inside of a js.erb file to pre populate some fields:
var orderData = <%= raw render :partial => 'orders/orders', formats: [:json], handlers: [:jbuilder], locals: {orders: #orders} %>;
I have a weird problem where if an error is thrown in the jbuilder template, it renders a missing template error. so
If _orders.json.jbuilder looks like this
json.array! orders do |order|
json.someProperty order.a_missing_property
end
I get this:
ActionView::Template::Error (Missing partial orders/orders with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee, :haml, :jbuilder, :riif]}
But if there is no error, this renders properly.
Any idea how my error is getting swallowed?
Update
I've created a demo app here: https://github.com/earnold/error-demo
If you load home/index you get a missing template error. If you comment out the bad line in the template, you render the template normally. What I am trying to do is make sure that errors aren't swallowed, but instead are shown on the page.
I was able to get an answer on Github here: https://github.com/rails/jbuilder/issues/40
Short version: this can be remedied by monkey patching Rails. Put this in an initializer and you're good to go.
if Rails.env.development? || Rails.env.staging?
module ActionView
class Template
protected
def handle_render_error(view, e) #:nodoc:
if e.is_a?(Template::Error)
e.sub_template_of(self)
raise e
else
assigns = view.respond_to?(:assigns) ? view.assigns : {}
template = self
unless template.source
# If an error occurs while the Jbuilder template is being rendered in
# in a nested context, you have a mismatch between the template format
# and the view context. Therefore, this block of code would raise
# a false exception (ActionView::MissingTemplate) and swallow the original
# error. This monkey patch tricks rails into thinking it was a json request
# so that refreshing the source hits the right partial
if template.formats == [:json]
view.lookup_context.formats = [:json]
end
template = refresh(view)
template.encode!
end
raise Template::Error.new(template, assigns, e)
end
end
end
end
end
I'm attempting to use render html: to render raw html from a controller action:
class SomeController < ApplicationController
def raw_html
render html: '<html><body>Some body text</body></html>'
end
end
However, when I run this controller action, I get a "Template is missing" error
I don't want to use a template, just render raw html.
The error I get is:
Processing by SomeController#raw_html as HTML
Parameters: {}
ActionView::MissingTemplate (Missing template some_controller/raw_html
with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder,
:raw, :ruby]}. Searched in: *
"/Users/doved/source/sample_app/app/views" *
"/Users/doved/.rvm/gems/ruby-2.0.0-p353#syp/gems/chameleon-0.2.4/app/views"
* "/Users/doved/.rvm/gems/ruby-2.0.0-p353#syp/gems/kaminari-0.15.1/app/views"):
app/controllers/some_controller.rb:14:in raw_html'
lib/middleware/cors_middleware.rb:8:incall'
I'm using Rails 4.0.2
What am I doing wrong?
html option was added to render method in Rails 4.1 version.
Checkout the discussion on this topic on Github
If you upgrade the Rails version to Rails 4.1 then you would be able to render html as
def raw_html
render html: '<html><body>Some body text</body></html>'.html_safe ## Add html_safe
end
With the current version of Rails 4.0.2, you would need to use
def raw_html
render text: '<html><body>Some body text</body></html>'
end
You are getting error as: ActionView::MissingTemplate
Because currently html option is not supported by render so the value passed with html option is ignored and Rails starts to look for a template some_controller/raw_html in views directory.
Possible duplicate of
How to return HTML directly from a Rails controller?
This should work for you:
render text: '<html><body>Some body text</body></html>'
I am new in rails and I want to implement chat in my rails app
following http://railscasts.com/episodes/260-messaging-with-faye,
but i m unable to render
controller :
def index #messages = Chat.all // all available chats
I get the following error:
Missing partial chats/chat with {:handlers=>[:builder, :erb, :coffee], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
* "/home/swagata/Desktop/swagata_new/swagata/app/views"
* "/home/swagata/.rvm/gems/ruby-1.8.7-p160#swagata/gems/devise-2.0.4/app/views"
I tried creating a partial name _chat.js.erb, but with no luck.
Any solutions?
Rails is trying to render an HTML snippet, but the only partial you've provided is marked as being a Javascript snippet.
You probably want an HTML-erb partial called _chat.html.erb
Create chat.erb and check if it's working or not
If you want to use a json call to render messages;
in your controller
def index
#messages = Chat.all
respond_to do |format|
format.js { render "chat" }
end
end
and in your view file, there should be a chat.js.erb file without underscore.
And your chat.js.erb may contain for example;
$('#chat').html("<%=j render '/messages' "); line to render messages at the div with id "chat".
and at the same directory there should be a _messages.html.erb file to render #messages.
I have a rails app (rails 3.1.3) that has a shopping cart model. I wanted to show a summary of the shopping cart in the layout so I created the partial views/carts/_cart.html.haml. My app was working fine and rendering the cart partial in every view. But when I installed devise 2.0, the partial could no longer be found for devise views. Instead, I would see the following error code when I tried to call a devise view:
ActionView::Template::Error (Missing partial views/carts/cart with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
* "/Users/cameronnorgate/Web Development/Practice Apps/1-Camerons Tea/pgktea/app/views"
* "/Users/cameronnorgate/.rvm/gems/ruby-1.9.2-p290#pgktea/gems/devise-2.0.4/app/views"
As you can see, it searches for the partial in app/views, but doesn't go all the way into the 'carts' folder in order to find the 'cart' partial. This is weird, because the code I had in the layout view specified the exact path (see below):
%body{:class => params[:controller]}
.master_container
.master_header
.inner_header
.cart
= render :partial => 'views/carts/cart', :object => #cart
Can anyone help me understand why my call to render the partial is not being found when inside a devise view?
The short term fix I've made for this is to bring the partial code back into the full layout file - so now devise doesn't have to go searching and everything works... but that's not ideal and it's cluttering up my code.
Thanks!
You should be able to specify the partial with just:
= render :partial => 'carts/cart', :object => #cart
The views/ part of your definition is probably throwing it off. app/views is implied, so when you specify views/carts/cart, it's probably not finding a views directory under app/views.
If this page can be access from other pages . then
= render :partial => '/carts/cart', :object => #cart
Is the correct way , because if this page open in other models then 'carts/cart' will not be available like if url is ex. 'localhost:3000/products' this page will give missing partial error so / will solve the issue and as other answers, 'views' is not needed