我目前只停留在一段代码上。请帮帮我们我正在开发一个在线商店。一切都很完美,直到我将这行代码(product_id: do product.id)
添加到我的主页。这是我尝试加载应用程序时的问题。
ruby 2.4.1p111 (2017-03-22 revision 58053) [i386-mingw32]
C:\Users\COMPUTER>cd desktop
C:\Users\COMPUTER\Desktop>cd trial
C:\Users\COMPUTER\Desktop\trial>cd depot
C:\Users\COMPUTER\Desktop\trial\depot>rails s
=> Booting Puma
=> Rails 5.0.5 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.10.0 (ruby 2.4.1-p111), codename: Russell's Teapot
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Started GET "/" for 127.0.0.1 at 2017-10-23 17:21:30 +0100
ActiveRecord::SchemaMigration Load (0.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by StoreController#index as HTML
Rendering store/index.html.erb within layouts/application
Rendered store/index.html.erb within layouts/application (4.0ms)
Completed 500 Internal Server Error in 1256ms (ActiveRecord: 0.0ms)
SyntaxError (C:/Users/COMPUTER/Desktop/trial/depot/app/views/store/index.html.erb:18: syntax error, unexpected ( arg, expecting keyword_do or '{' or '('
d to Cart' , line_items_path (product_id: product.id) );@ou
^
C:/Users/COMPUTER/Desktop/trial/depot/app/views/store/index.html.erb:18: syntax error, unexpected ')', expecting keyword_end
th (product_id: product.id) );@output_buffer.safe_append='
^
C:/Users/COMPUTER/Desktop/trial/depot/app/views/store/index.html.erb:24: syntax error, unexpected keyword_ensure, expecting end-of-input
ensure
^):
app/views/store/index.html.erb:18: syntax error, unexpected ( arg, expecting keyword_do or '{' or '('
app/views/store/index.html.erb:18: syntax error, unexpected ')', expecting keyword_end
app/views/store/index.html.erb:24: syntax error, unexpected keyword_ensure, expecting end-of-input
Rendering C:/Ruby24/lib/ruby/gems/2.4.0/gems/actionpack-5.0.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
Rendering C:/Ruby24/lib/ruby/gems/2.4.0/gems/actionpack-5.0.5/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered C:/Ruby24/lib/ruby/gems/2.4.0/gems/actionpack-5.0.5/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (88.0ms)
Rendering C:/Ruby24/lib/ruby/gems/2.4.0/gems/actionpack-5.0.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered C:/Ruby24/lib/ruby/gems/2.4.0/gems/actionpack-5.0.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (32.0ms)
Rendering C:/Ruby24/lib/ruby/gems/2.4.0/gems/actionpack-5.0.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered C:/Ruby24/lib/ruby/gems/2.4.0/gems/actionpack-5.0.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (8.0ms)
Rendered C:/Ruby24/lib/ruby/gems/2.4.0/gems/actionpack-5.0.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (9608.1ms)
这是主页.....
<p id="notice"><%= notice %></p>
<h1>Your Pragmatic Catalog</h1>
<% cache @products do %>
<% @products.each do |product| %>
<% cache @product do %>
<div class="entry">
<h3><%= product.title %></h3>
<%= image_tag(product.image_url) %>
<%= sanitize(product.description) %>
<div class="price_line">
<span class="price"><%= number_to_currency (product.price) %></span>
<%= button_to 'Add to Cart' , line_items_path (product_id: do product.id) %>
</div>
</div>
<% end %>
<% end %>
<% end %>
这是控制器......
class StoreController < ApplicationController
def index
@products = Product.order(:title)
end
end
答案 0 :(得分:2)
删除line_items_path
及其参数之间的空格(并删除此do
关键字):
<%= button_to 'Add to Cart', line_items_path(product_id: product.id) %>