No Method Error editing Shopify metafield data with ruby on rails via a form -


as part of customisation i'm doing shopify site, i'm trying write tool allows specific metafield edited.

on index page, i'll listing various collections, products, pages , blog articles associated specific metafield want user able edit via form.

... life of me, can't see i've missed!! in resolving appreciated :)

so ... here go! when user clicks 'edit' (which should take them form edit particular metafield collection, product, page or blog article), i'm getting error in browser :

nomethoderror in metafields#edit  showing /users/james/code/test-app/app/views/metafields/_form.html.erb line #1 raised:  undefined method `shopify_api_metafield_path' #<#<class:0x007facf51992a0>:0x007facf520fec8>  extracted source (around line #1): 1: <%= form_for(@metafield) |f| %> 

the model "metafield.rb" looks this:

class metafield < activerecord::base   attr_accessible :namespace, :key, :value, :value_type, :description, :id end 

the controller "metafields_controller.rb" has following method defined:

  # /metafields/1/edit   def edit     @metafield = shopifyapi::metafield.find(params[:id])   end 

the file "/views/metafields/index.html.erb" looks this:

<h1>listing metafields</h1>  <table>   <tr>     <th>namespace</th>     <th>key</th>     <th>value</th>     <th>value type</th>     <th>description</th>     <th>id</th>     <th></th>   </tr>  <% @metafields.each |metafield| %>   <tr>     <td><%= metafield.namespace %></td>     <td><%= metafield.key %></td>     <td><%= metafield.value %></td>     <td><%= metafield.value_type %></td>     <td><%= metafield.description %></td>     <td><%= metafield.id %></td>     <td><%= link_to 'edit', edit_metafield_path(metafield) %></td>   </tr> <% end %> </table> 

the file "/views/metafields/edit.html.erb" looks this:

<h1>editing metafield</h1>  <%= render 'form' %>  <%= link_to 'back', metafields_path %> 

the file "/views/metafields/_form.html.erb" looks (of which, apparently, line #1 throwing error...):

<%= form_for(@metafield) |f| %>   <% if @metafield.errors.any? %>     <div id="error_explanation">       <h2><%= pluralize(@metafield.errors.count, "error") %> prohibited metafield being saved:</h2>        <ul>       <% @metafield.errors.full_messages.each |msg| %>         <li><%= msg %></li>       <% end %>       </ul>     </div>   <% end %>    <div class="field">     <%= f.label :namespace %><br />     <%= f.text_field :namespace %>   </div>   <div class="field">     <%= f.label :key %><br />     <%= f.text_field :key %>   </div>   <div class="field">     <%= f.label :value %><br />     <%= f.text_field :value %>   </div>   <div class="field">     <%= f.label :value_type %><br />     <%= f.text_field :value_type %>   </div>   <div class="field">     <%= f.label :description %><br />     <%= f.text_field :description %>   </div>   <div class="actions">     <%= f.submit %>   </div> <% end %> 

thanks in advance!

it`s not idea nest forms in view partials in _form.html.erb.

<%= form_for(@metafield) |f| %>   <% if @metafield.errors.any? %>     <div id="error_explanation">       <h2><%= pluralize(@metafield.errors.count, "error") %> prohibited metafield being saved:</h2>        <ul>       <% @metafield.errors.full_messages.each |msg| %>         <li><%= msg %></li>       <% end %>       </ul>     </div>   <% end %> 

you can try use helper:

<%= error_messages_for 'metafield' %> 

instead of using form_for() helper.

update

if wish use form_for() helper correct define metafield model way:

class shopifyapi::metafield < activerecord::base { } 

since form_for() helper tries figure out path view rendered on form submission. path returned shopify_api_metafield_path() helper undefined method error message.

regarding error_messages_for() helper, not translated html form tag , can used inside view partial without nesting html forms. see more here


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -