Reputation: 79
I'm facing the following error message:
ExecJS::ProgramError in Restaurantes#index Showing C:/rubyProject/vota_prato/app/views/layouts/application.html.erb where >line #6 raised:
TypeError: O objeto não dá suporte para a propriedade ou método Rails.root: C:/rubyProject/vota_prato
Application Trace | Framework Trace | Full Trace app/views/layouts/application.html.erb:6:in >`_app_views_layouts_application_html_erb__971963449_62998908' Request
I fixed it removing the line:
true %>
from my app/views/layouts/application.html.erb file
after I did it, I faced the other problem =(. I created a action destroy at one controller:
class RestaurantesController < ApplicationController
def destroy
@restaurante = Restaurante.find(params[:id])
@restaurante.destroy
redirect_to(action: "index")
end
def index
@restaurantes = Restaurante.all
end
def show
@restaurante = Restaurante.find(params[:id])
end
end
and my index.html.rb file:
<h1>Listagem de Restaurantes</h1>
<table>
<tr>
<th>ID</th>
<th>Nome</th>
<th>Endereço</th>
<th>Especialidade</th>
</tr>
<% @restaurantes.each do |restaurante| %>
<tr>
<td><%= restaurante.id %></td>
<td><%= restaurante.nome %></td>
<td><%= restaurante.endereco %></td>
<td><%= restaurante.especialidade %></td>
<td><%= link_to 'Mostrar', action: 'show', id: restaurante %></td>
<td>--</td>
<td><%= link_to 'Deletar', {action: 'destroy', id: restaurante},{method: "delete"} %></td>
</tr>
<% end %>
</table>
when clicked at Deletar link, it executed same action as Show action, I don't know why
Upvotes: 1
Views: 11651
Reputation: 11
You need to install nodejs to fuse the turbolliks; )
Follow the link: https://nodejs.org/en/download/
Upvotes: 1
Reputation: 438
First of all, I'm sorry for my english if it's too bad... This error happened to me a couple months ago. There wasn't a problem with ruby, rails gem, or any other gem installed.
These are my specs:
After insalling the RubyInstaller, I created a new project, but I had the same error like you:
ExecJS::ProgramError in home#index Showing C:/ruby_project/app/views/layouts/application.html.erb where line #6 raised:
TypeError: Object doesn't support this property or method
DEFINITE SOLUTION IS:
<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
NOTE: For linux/mac users, just install ruby and rails by RVM (Ruby Version Manager). You won't have any problem, I tell you this by experience.
For installing RVM on your linux/mac terminal I will recommend you these tutorials below. I've tried them and they work!
Please comment if this worked for you or not...
Regards.
Upvotes: 5
Reputation: 71
To solve the ExecJS problem in Windows, change the parameter application
to default
in lines 5 and 6 of the views/layouts/aplication.html.erb file.
The file should look like this:
<%= stylesheet_link_tag 'default', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>
This worked for me.
Upvotes: 7
Reputation: 79
Thanks, it works, but I think it worked because I installed the nodeJS. After I restarted my computer, however both solutions worked
Upvotes: 0
Reputation: 33
Can't tell much about your JS problem because not enough information.
As for the link part, your delete link should look like this:
<%= link_to 'Deletar', restaurante_path(restaurante), method: :delete %>
Also make sure that you have jquery-ujs
included in your application.js
(this is what understands the method: :delete
part in your link and POSTs a form rather than GETting a page)
BTW, do not ask two question in one. Make them separate questions.
Upvotes: 1
Reputation: 575
Have you uncommented the line:
gem 'therubyracer', platforms: :ruby
from your gemfile? Do that, run "bundle install" and try again. The delete method relies on some Javascript. It's rubyracer or some nodejs thing you can use instead, I can't remoember what it is called.
Upvotes: 0