MissingTemplate Frustrating behavior - ruby

I am completing this rails tutorial
Everything was going along smoothly even though im working on windows, until i hit the partials section.
I pretty much copy pasted everything from the tutorial. I made sure that the underscore character in the partial filenames is an actual underscore.
I have placed the partials in the
app/views/layouts/
path as the tutorial suggests and included the
<%= render 'layouts/shim' %>
in my application.html.erb file. This results in the
ActionView::MissingTemplate in StaticPages#home
Showing E:/ruby/my_projects/sample_app/app/views/layouts/application.html.erb where line #9 raised:
Missing partial layouts/shim with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "E:/ruby/my_projects/sample_app/app/views"
Extracted source (around line #9):
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %> #this is line number 9
</head>
<body>
<%= render 'layouts/header' %>
I have tried placing the files directly in views folder as well as in the static pages folder.
I restarted the rails server multiple times during this process.
Anybody has any ideas?

Ok I guess its a ridicules mistake but it took me so long to figure it out. It should be obvious for me that windows hides extensions so after i misnamed my file the first time and tried to fix it (rename it) it already hid the .erb extension. So it had an .erb.erb extension and because of that it didnt work.
Thanks everyone that tried to help.

Related

Errno::EACCES error when testing code in development on localhost

Get this error when running this code:
<% content_for :game do %>
<% gamefolder = Dir.open(`#{Rails.root}/public/browserGames/#{#browserGame.slug}`) %>
<% gameFolder.each do |file| %>
<% if file.match?(/.js/) %>
<script src=<%= `#{Rails.root}/public/browserGames/#{#browserGame.slug}` + file %>></script>
<% end %>
<% end %>
It stops me on line 2 and gives the Errno::EACCES error. I am simply running this on localhost in development mode. Wanting to make sure everything works before I try to deploy and find similar issues.
What I am trying to accomplish with this code is to load the js files for the specific game trying to be played in the window.
I am also open to trying other ways of achieving the goal, but I have different games on here and want to make sure I am only loading the specific files for the selected game.
Any help is greatly appreciated.
Use
Dir["#{Rails.root}/public/browserGames/test/*.js"]
instead of opening open for dir.
and use <script src="<%= file %>"></script>

Unable to implement recaptcha gem options in a Rails 4.2 app

I am using the recaptcha gem version 4.0, and therefore placed <%= recaptcha_tags %> inside a form. There are options that you are supposed to be able to implement to change the size (normal or compact?) and theme (light or dark).
I reviewed numerous posts here and elsewhere without finding a syntax that works. Here are several options I used based on what I found:
<%= recaptcha_tags :display => {:size => 'compact', :theme => 'dark'} %>
<%= recaptcha_tags :display => {size: 'compact', theme: 'dark'} %>
<%= recaptcha_tags :size => 'compact'} %>
<%= recaptcha_tags size: 'compact'} %>
Nove of these worked. I also removed the options from the recaptcha tags and modified the gem's client_helper.rb file. I cut all of the width and height styles were cut in half. That didn't work either. I'd rather use the options that can be supplied in the recaptcha tags. Anybody know how to do that? Thanks in advance! Jay
check the generated tag, if you pass size: 'compact' it should create a data-size="compact" attribute
https://github.com/ambethia/recaptcha/blob/master/lib/recaptcha/client_helper.rb#L70-L71
if that does not work, update to latest ... maybe bundle open recaptcha ... if size should not be data-size but regular size then this might be a bug and needs a proper fix ... still open the gem, turn it remove :size from the list and see if that fixes it
--retransmitted from grosser

Middleman Blog: Custom layout not loading

In Middleman, I am trying to set up a blog site, using custom layout for the blog. My problem is that the main layout is loading, but the blog layout for my articles is not. The article files are being served in with their plain body.
In source/layouts/ I have two files: layout.erb and article_layout.erb.
My intent is to use article_layout.erb for my blog articles.
In config.rb I have the following:
activate :blog do |blog|
blog.sources = "articles/{category}/{year}-{month}-{day}-{title}.html"
blog.layout = "article_layout"
end
I have also tried moving article_layout.erb to source/articles/ as well as prepending the config.rb file like this: blog.layout = "layouts/article_layout"
Another failed approach is to comment out the above option and configure the layout by adding this line instead: page "/articles/*", layout: "article_layout".
So far none of these approach show a difference. Since the default layout is not being rendered I would expect some sort of error message if the path to the layout cannot be found, but nothing shows up.
I managed to replicate your problem with my own Middleman blog setup.
The docs are unclear on this because there is a broken link in the layout section of Blogging.
You need to use the nested layout feature of Middleman and wrap your custom layout in:
<% wrap_layout :layout do %>
<% end %>
So your article_layout.erb would look something like this:
<% wrap_layout :layout do %>
<div class="article-container">
<article>
<h2 class="article-title"><%= current_page.title %></h2>
<%= yield %>
</article>
</div>
<% end %>
And keep your custom layout in the source/layouts folder.
Here are the docs for Nested Layouts for your reference.
I hope this helps.

Rails, Twitter Bootstrap, Simple Form, Heroku - Odd error when using ":wrapper => :prepend do" to get an add-on span

I have the following code in a form partial:
<%= f.association :client %>
<%= f.input :url, :wrapper => :prepend do %>
<%= content_tag :span, "http://www.", :class => "add-on" %>
<%= f.input_field :url, :class => 'span4' %>
<% end %>
Trying to load anything to do with this form partial e.g. new/edit etc causes Heroku to error. It works flawlessly on localhost.
The only obvious error in the Heroku logs is:
ActionView::Template::Error (undefined method `source' for nil:NilClass):
I'm afraid I don't really understand that but thought it might help anyone trying to answer this.
If I change the form partial code it works on Heroku no problem at all e.g.
<%= f.input :url, :input_html => {:class => 'span4' } %>
Obviously I lose my nice bootstrap add-on span so I'd rather find out what the issue is rather than running around it.
Shot in the dark, but maybe an initializer that sets up the prepend wrapper (like initializers/simple_form.rb or initializers/simple_form_bootstrap.rb) is not being run by Heroku, either because it's not checked into git, or because of some environment-specific logic in the initializers or environment files.
Well after testing and some help from Dan I finally got to the bottom of it. Unfortunately, it seems to be quite localised to my situation though.
But just in case anyone stumbles across this, the error I had was the following:
ActionView::Template::Error (undefined method `source' for nil:NilClass):
That was in the log and was THE SAME when I followed Dan's advise to turn on error reporting on the production site (set consider_all_requests_local = true in config/environments/production.rb).
I thought that the error was being caused in the template, however, it was some validation rules in the model. The validation rules for me where some regex to stop the user starting the input with a certain string. They worked perfectly fine on my local, but Heroku really wasn't liking it!
I removed those validation rules and voila, my nice bootstrap add-on span was working perfectly.

ArgumentError (2 for 1):Rails3.1.0 <%= stylesheet_link_tag "application" %>

wrong number of arguments (2 for 1)
Extracted source (around line #5):
<html>
<head>
<title>Assets</title>
<%= stylesheet_link_tag 'application'%>
<%= javascript_include_tag %>
<%= csrf_meta_tags %>
</head>
I've tried:
<%= stylesheet_link_tag :all %>
but I got:
<link href='assets/all.css' ...>
What confused me most is that I run an app on my MAC OS with almost the same config except mysql&Gemfile and it works well, but when I turn to centos5 I got these errors!
I had this problem too, and it turned out to be due to some code still targeting an older rails version, before the new asset pipeline work. Specifically, I had a redmine plugin using the method image_path with two arguments:
image_path('database_refresh.png', :plugin => 'redmine_rate')
This was no longer possible, and needed to be replaced with code that explicitly calculated the plugin specific path. I used code based on the wiki document at http://www.redmine.org/boards/3/topics/31445#Links-and-paths-to-plugin-assets
Note that this solution was for a problem I had with redmine, not rails, but could in fact be relevant.
<%= stylesheet_link_tag "application" %>
Should be fine. Rails has an assets pipeline to merges all the different stylesheets into one for the productive environment. I think it is an error in the assets pipeline.
Here is a good tutorial about this pipeline:
http://railscasts.com/episodes/279-understanding-the-asset-pipeline
To possibly fix your error have a look at config/environments/production.rb and try to set this to true
config.assets.compile = true
Another problem might be the configuration in the application.css have you perhaps deleted the comments or added something?
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree .
*/
But these are just guesses... but I hope this leads you towards the solution of the problem.

Resources