简体   繁体   中英

is missing a template for request formats: text/html

I have Term and Phrase models and I am adding Nested Resources. I want to get the Term Id for Phraes_term to create a data pair

Example: Term 1 and Phrase 2. But when you press the new button from show.html.erb term, an error will occur

-->error :PhrasesTermsController#new is missing a template for request formats: text/html

form.html.erb -(phrases_term).

<%= form_with(model: phrases_term, local: true) do |form| %>
  <% if pharases_term.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(pharases_term.errors.count, "error") %> prohibited this phrase from being saved:</h2>

      <ul>
      <% pharases_term.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :ID %>
    <%= form.number_field_tag :ID %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>

(phrases_term) -new.html.erb

<%= render 'form', phrases_term: @phrases_term %>

Phrases_terms_controller.rb

class PhrasesTermsController < ApplicationController
  before_action :authenticate_user!
  before_action :set_term

  def new
    @phrases_term = PhrasesTerm.new
  end

  def create
    @phrases_term = @term.phrases_term
    @phrases_term.user = current_user
    @phrases_term.save
    redirect_back(fallback_location: root_path)
  end

  private

  def phrases_term_params
    params.require(:phrases_term).permit(:term_id)
  end

  def set_term
    @term = Term.find(params[:term_id])
  end
end

routes.rb

resources :terms do
    resources :phrases_terms, only: [:create, :destroy, :new]
  end

(Term) Show.html.erb

<td><%= link_to 'New', new_term_phrases_term_path(@term) %></td>
(phrases_term).

_form.html.ebr
<%= form_with(model: phrases_term, local: true) do |form| %>
  <% if pharases_term.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(pharases_term.errors.count, "error") %> prohibited this phrase from being saved:</h2>

      <ul>
      <% pharases_term.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :ID %>
    <%= form.number_field_tag :ID %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
(phrases_term)
 new.html.erb
<%= render 'form', phrases_term: @phrases_term %>

This means you do not have a app/views/phrases_term(s)/new.html.erb file. I'm unsure if you've namespaced the files under 'phrases_term' or 'phrases_terms'.

Make one in the correct directory, populate it, and it will load.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM