Ruby on Rails+Solidus电商站Google索引失败:name字段值类型无效排查修复
Let's break down exactly what's causing this Google indexing error and how to fix it in your Solidus/Rails code.
The Root Cause
The error Google is flagging comes from a mismatch in how you've applied Schema.org's name property. Right now, you've added itemprop="name" directly to the <a> (link) tag in this line:
<%= link_to(truncate(product.name, length: 50), url, class: 'info', itemprop: "name", title: product.name) %>
Google's structured data parser expects the name field for a Product to be a plain text value, but instead it's reading an entire HTML anchor element. This type mismatch triggers the "invalid value type for 'name' field" error.
Fixing the Rails Code
You need to separate the link functionality from the Schema.org name property. Here are two clean, Rails-friendly ways to adjust your ERB:
Option 1: Wrap the text in a span with itemprop
Keep the link intact, but move the itemprop="name" to a <span> inside the link. This ensures Google picks up plain text for the name while keeping the link functional:
<%= link_to url, class: 'info', title: product.name do %> <span itemprop="name"><%= truncate(product.name, length: 50) %></span> <% end %>
Option 2: Add a fallback for empty product names (extra safeguard)
If any of your products might have a blank name, add a fallback to avoid another validation error:
<%= link_to url, class: 'info', title: product.name do %> <span itemprop="name"><%= truncate(product.name.presence || 'Unnamed Product', length: 50) %></span> <% end %>
Checking for Other Potential Issues
Your core ERB syntax doesn't have obvious syntax errors, but double-check these details to avoid other indexing hiccups:
- Confirm your
Offermarkup is correct: your current code properly setscontentattributes forpriceandpriceCurrency, which is good practice for Schema.org. - Make sure
product.gallery.images.firstnever returnsnil—if a product has no images, add a fallback image to avoid breaking theimageitemprop.
Verifying the Fix
After updating the code, use Google's structured data validation tool (available in Google Search Console or as a standalone tool) to confirm the "invalid value type" error is resolved. Run a test on your product listing page to ensure all Schema.org properties are correctly parsed.
内容的提问来源于stack exchange,提问作者Charlie_oscar

