I have a Rails app with Haml views which runs fine locally and also on another host. But after deploying to Heroku, the first request gets an error, se the log below:
Started GET "/" for 88.159.5.1 at 2012-11-02 07:03:56 +0000
- - Processing by SessionsController#new as HTML
- - Rendered sessions/new.html.haml within layouts/application (403.5ms)
- - Completed 500 Internal Server Error in 497ms
- - ActionView::Template::Error (syntax error on line 18, col 4: `all: all'):
- - 1: .sixteen.columns
- - 2: #loginblock
- - 3: .content_title.general
- - 4: %h2= I18n.t :login_title
- - 5: .content
- - 6: = render("layouts/message")
- - 7: = form_tag(sessions_path, :class => 'form') do
- - app/views/sessions/new.html.haml:4:in `_app_views_sessions_new_html_haml___1472882735787050115_50827800'
Strange thing is: line 18 doesn't exist in that view, it has only 17 lines. And on line 4 I don't see anything wrong? Probably has something to do with Haml or Haml gem not working correctly? See is the view file below. Thanks for any input!
.sixteen.columns
#loginblock
.content_title.general
%h2= I18n.t :login_title
.content
= render("layouts/message")
= form_tag(sessions_path, :class => 'form') do
.field
= label_tag I18n.t :form_email
= text_field_tag :email
.field
= label_tag I18n.t :form_password
= password_field_tag :password
.field
= submit_tag I18n.t(:login_title), :class => 'button white'
.clear
Found it: the indentation in the yaml file was 4 spaces instead of 2, so a level too deep. For some reason my local Rails setup accepts this, but the Heroku rails setup doesn't. So after correcting the indentation, everything was OK on Heroku.
Related
I'm having hard time getting rails_admin to work without devise.
I tried https://gist.github.com/Overbryd/1068094
as well removing all the devise related code from my user model and routes
However, I'm getting the following error:
ActionView::Template::Error (Could not find a valid mapping for # From here
6: - if _current_user
7: - if user_link = edit_user_link
8: %li= user_link
9: - if logout_path.present?
10: %li= link_to content_tag('span', t('admin.misc.log_out'), :class => 'label label-important'), logout_path, :method => Devise.sign_out_via
11: - if _current_user.respond_to?(:email) && _current_user.email.present?
devise (2.2.3) lib/devise/mapping.rb:42:in find_scope!'
/home/eugene/.bundler/ruby/1.9.1/rails_admin-75079da0906e/app/helpers/rails_admin/application_helper.rb:36:inlogout_path'
Assuming you have a route similar to this:
get "logout" => "sessions#destroy", as: "logout"
Then you can do this:
- if _current_user
- if user_link = edit_user_link
%li= user_link
%li= link_to content_tag('span', t('admin.misc.log_out'), class: 'label label-important'), '/logout'
That simply replaces the Devise nonsense with a link to your overall sessions destroy route. You can also delete the logout_path method in the Application Controller as well.
I am running a pretty straight forward Rails 3.2 app on Dreamhost (I know its lame).
The error is:
NoMethodError in Products#edit
Showing /home/emeraldcityguitars/emeraldcityguitars.com/releases/20120318040051/app/views/products/edit.html.erb where line #47 raised:
undefined method `klass' for nil:NilClass
Extracted source (around line #47):
44: <div id="interior_sub_head"><h5 id="sub_green_head"><%= #product.title %></h5></div>
45: <div id="interior_pad">
46:
47: <%= nested_form_for #product, :html => { :multipart => true } do |f| %>
48: <%= f.error_messages %>
49:
50: <fieldset>
It sounds like #product is returning nil, but if you look at line 44, it didn't error when requesting #product in that case?
any ideas?
EDIT
Full Product#edit view: https://gist.github.com/2081340
+
_photo_fields.html view: https://gist.github.com/5af2f88f29c21e24b42c
Thanks
I had the same problem and I made two changes, unfortunately not separately, and one or both solved the problem.
First, in your controller do you build a photo in your edit method?
#product.photos.build if #product.photos.empty?
I found that in the comments on this blog post.
Second, I added a symbol for the nested class to the 'link_to_add' line, which you already have.
I was switching from a has_many to has_one and was getting this same error. Azolo's response fixed my issue.
Removed the <%= f.link_to_add......%> tag and all is working nicely!
[Edit: The solution to this problem is in the routes.rb file. I have "resource" instead of "resources" on the ":comments" line]
I'm following the guide at http://guides.rubyonrails.org/getting_started.html, and I'm at section 9 "Deleting Comments". I've been following the guide step-by-step, and have been cutting/pasting the code instead of typing it, so I doubt I have a typo - more like I missed a step. I'd like to fix this before continuing with the tutorial as I'm brand-spanking-new to Rails and it's still pretty foreign to me.
Any idea what's wrong?
An except from my routes.rb:
resources :posts do
resource :comments
end
When I attempt to view a post with a comment, I receive the following error:
NoMethodError in Posts#show
Showing C:/Documents and Settings/stevez/Desktop/blog/app/views/comments/_comment.html.erb where line #12 raised:
undefined method `post_comment_path' for #<#<Class:0x1f13238>:0x1eecf70>
Extracted source (around line #12):
9: </p>
10:
11: <p>
12: <%= link_to 'Destroy Comment', [comment.post, comment],
13: :confirm => 'Are you sure?',
14: :method => :delete %>
15: </p>
Trace of template inclusion: app/views/posts/show.html.erb
Rails.root: C:/Documents and Settings/stevez/Desktop/blog
Application Trace | Framework Trace | Full Trace
app/views/comments/_comment.html.erb:12:in `_app_views_comments__comment_html_erb___131033543_18407100'
app/views/posts/show.html.erb:19:in `_app_views_posts_show_html_erb___843714715_14332200'
app/controllers/posts_controller.rb:18:in `show'
Request
Parameters:
{"id"=>"2"}
Show session dump
Show env dump
GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_ACCEPT_CHARSET: "ISO-8859-1,utf-8;q=0.7,*;q=0.3"
HTTP_ACCEPT_ENCODING: "gzip,deflate,sdch"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8"
HTTP_CACHE_CONTROL: "max-age=0"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "localhost"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"
Response
Headers:
None
In your routes, the routing to comments should be plural as well, meaning resources instead of resource. Try to do it like this:
resources :posts do
resources :comments
end
How to solve kaminari problem with haml? I m using haml haml (3.1.4)
and kaminari 0.13.
my index file looks like:
%h1 Listing customers
=paginate(#customers)
%table.index-list
%tr
%th Name
.....
but i m getting an error
undefined local variable or method `prev_span_tag'
for #<Kaminari::Helpers::Paginator:0xa848978>
Extracted source (around line #10):
7: paginator: the paginator that renders the pagination tags inside
8: -%>
9: <%= paginator.render do -%>
10: <nav class='pagination'>
11: <%= current_page > 1 ? prev_link_tag : prev_span_tag %>
12: <% each_page do |page| -%>
13: <% if page.current? -%>
Thanks.
I found this question : Rails heroku help kaminari view error. So i'd delete (and backup if necessary) your current views and regenerate them again
I have nested resources like this in my routes.rb - (my rake:routes gist)
namespace(:admin) do
resources :restaurants do
resources :menus
resources :menu_items
end
end
In the controller:
def new
#restaurant = Restaurant.find(params[:restaurant_id])
#menu_item = #restaurant.menu_items.build
end
Trying to create a new MenuItem (action #new), by the url: http://127.0.0.1:3001/admin/restaurants/1/menu_items/new I get the error:
NoMethodError in Admin/menu_items#new
Showing /home/fps/workspace3/peded/app/views/admin/menu_items/_form.html.erb where line #1 raised:
undefined method `admin_menu_items_path' for #<#<Class:0xb6582d78>:0xb6581f2c>
Extracted source (around line #1):
1: <%= form_for #menu_item do |f| %>
...
How do I make this form work? It was created out of a nifty:scaffold
UPDATE
I also tried this in the _form:
<%= form_for [:restaurant, #menu_item] do |f| %>
But ended with a similar error:
Showing /home/fps/workspace3/peded/app/views/admin/menu_items/_form.html.erb where line #1 raised:
undefined method `restaurant_admin_menu_items_path' for #<#<Class:0xb68162b0>:0xb6813dd0>
Extracted source (around line #1):
1: <%= form_for [:restaurant, #menu_item] do |f| %
Should I file a bug?
form_for([#restaurant, #menu_item])
I think the problem is in the form. This worked for me:
<%= form_for(#menu_items, :url => restaurant_menu_items_path(#menu_items.restaurant)) do |f| %>
I'm having the same issue. The only solution I have found is to pass a url to the form_for.
<% url = (action_name == "new" ? {:action=>"create", :controller=>"admin/menu_item"} : {:action=>"update", :controller=>"admin/menu_item"})%>
<%= form_for [#restaurant ,#menu_item], :url=>url do |f| %>
One additional note, you will not get params[:menu_item] back, instead you will see params[:admin_menu_item].
Hope that helps you out!
You can look up your routes by running on the command line.
rake routes
It looks like you're calling your routes incorrectly.
Array notation would be:
form_for([:admin, #restaurant, #menu_item])
And the named route for create:
admin_restaurant_menu_items_path(#restaurant)
Dealing with nested resources and namespaces is a Vietnam (pita).
Here is my nasty solution:
= form_for #admin_menu_item,
:url => (#admin_menu_item.try(:new_record?) ?
admin_restaurant_menu_items_path(#admin_restaurant) :
admin_menu_item_path(# admin_menu_item)) do |f|
...
I hope you can help.
The only solution that worked for me correctly (for both new and edit resource) was:
form_for #menu_item, :url => url_for([:admin, #restaurant, #menu_item])
I'm using Rails 5 (not that I imagine it matters) and this worked for me:
= simple_form_for [:admin, #restaurant, #menu_item] do |f|
The fact that it's simple_form_for rather than form_for probably doesn't matter either.
Funnily enough, I'm building an app with the same exact resource names.