So I have a simple Rails form that is sent to controller admin, action checkLogin. If the credentials are correct, redirect the user to a new view called main.html.erb. Now in my controller I have literally tried everything, from render 'main'; to redirect_to. But I keep getting the following error:
ActionView::MissingTemplate (Missing template admin/activate with {
:handlers=>[:rjs, :rhtml, :rxml, :builder, :erb],
:formats=>[:js, :"application/ecmascript", :"application/x-ecmascript", :"*/*"],
:locale=>[:en, :en]} in view paths "/home/xxx/xxx/xxx/rails/beta/app/views"
Is this a routing issue, or what?
Try render :file => 'admin/main.html.erb' to specify the exact file.
The problem is the render call is looking for a file that matches the name of your controller action, and it isn't finding it. So, specify the exact file and you should be ok.
FYI if you call render 'main' then it will try to render the view associated with your "main" action, which may not work if you don't have a "main" action.
Also, be sure you mean to render. If you DO have a main action and you want the stuff that's defined in that action to happen then you need to redirect_to main_whatever_path.
Have you add the 'checkLogin' to routes. try this, in your routes.rb
resources :admin do
member do
get 'checkLogin'
end
end
**NOTE : get 'checkLogin' might be post 'checkLogin' according to your case..
and inside your controller action 'checkLogin', render a partial
render :partial => 'main'
Related
Hi I am pretty new to rails and mvc, but my application has users and I want to allow someone to quickly sign up from the home page using a bootstrap modal and to allow them to sign up through a normal sign up page.
In my Users controller I have created a partial for the modal _newUserModal.html.erb and I want to use this in the index action from my Home controller.
I have read that I should load partials from another controller inside the action. So I am trying the following
class HomeController < ApplicationController
def index
render 'users/newUserModal'
end
end
This is giving me the error
Template is missing
Missing template users/newUserModal with {:locale=>[:en],
:formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "/home/jeff/Development/iHaul/app/views" * "/home/jeff/Development/iHaul" * "/"
I have a feeling I am missing something small but I can't figure it out.
Ok by moving the render to the bottom of my home.html.erb it has allowed my code to work. I know this isn't the best practice but it works for now. If anyone can shed some light on the issue that would help a lot.
My advice for anyone who is using partials from another controller is do not give a partial the same name as a method. If you do you have to specifically tell render to use the partial file with
render :partial => 'controller/action'
if your careful render works normally, although the above is more readable.
OK my remaining question is wrong. After a nights sleep I realized I am not using the MVC pattern for what it is designed for. I was being to precious with using #user = User.new . If I just use that in the index function of my home controller everything works beautifully.
I have a polymorphic Review model. The namespaced model User::Library::Publication is reviewable. The reviews are created properly, but when I try to display them through a partial, Rails looks up the wrong directory.
In my view:
<%= render #review %>
I get this error:
Missing partial user/library/reviews/review with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder]}
Rails is apparently looking for the review partial within the namespace's directory views/user/library instead of the /views/reviews. Any idea why this is happening?
If you want to remove namespacing from the partial template path, you can set the prefix_partial_path_with_controller_namespace variable in your config/application.rb:
# config/application.rb
config.action_view.prefix_partial_path_with_controller_namespace = false
This will load partial paths as you define them (without the namespace).
You can see the original Pull Request here.
If you use name spaces you have to create folders/sub folders so Rails is not looking at the wrong place.
If you want to force the partial path just use:
render :partial => "review"
And create rename the review.html.erb file to _review.html.erb
I have a problem when trying to render a controller action. Following the documentation I should be able to use:
render 'user/new' or
render template: 'user/new' or
render :action => "new", :controller => "users"
Although I get a template missing exception and I'm not shure, why. Using a form for works, but it's stupid to copy exactly the same form.
I'm pretty messed, so I'm shurely missing something, but I don't get it.
Any hints?
EDIT: I'm calling from the GroupsController where I want to render the new-user-form. Did a test with only scaffolded models and I get the same error.
ActionView::Template::Error (
Missing partial users/new with {:locale=>[:de], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "/Users/rob/Development/projects/test/app/views"
* "/Users/rob/.rvm/gems/ruby-1.9.3-p362/gems/oembed_provider_engine-0.2.0/app/views"
* "/Users/rob/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.2.3/app/views"
):
Partial templates' filename always begins with an underscore. So you need a "_new.html.erb" file in your "user" view to render.
If I'm not mistaken, the default scaffolding creates a "_form.html.erb" for each model to render it in new and edit actions both. You can just render that instead of the whole "new" view.
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
I am trying to render a partial on a collection with <%= render #posts %> which returns the error:
Missing partial posts/post with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}
However it works if i use <%= render :partial => 'post', :collection => #posts %>
I have _post.html.erb in the same folder which uses post variable (from posts)
Why would the former example way of rendering a partial on a collection not work, but the latter example does work?
EDIT: I should specify I'm using Rails 3.2.1
The default of to_partial_path for your objects is always scoped under a view folder for the class, so your partial must be in the posts view folder.
When you use the form render :partial => 'post' it looks in the folder of the controller you are currently under.
I suspect that you are not working in the PostsController view folder, which would explain the behavior you are seeing. If you are working in the posts view folder, then something else must be going on so if you could provide more detail that would help diagnose it further