request
の部分パーツを別の部分図に含めることを試みています。Rails:別の部分図でパーシャルを使用できません
私はrequest
というモデルを持っています。
class CreateRequests < ActiveRecord::Migration[5.0]
def change
create_table :requests do |t|
t.string :name
t.string :email
t.string :phone
t.string :product
t.string :details
t.timestamps
end
end
end
私は
<%= form_for(request) do |f| %>
<% if request.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(request.errors.count, "error") %> prohibited this request from being saved:</h2>
<ul>
<% request.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :phone %>
<%= f.text_field :phone %>
</div>
<div class="field">
<%= f.label :product %>
<%= f.text_field :product %>
</div>
<div class="field">
<%= f.label :details %>
<%= f.text_field :details %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
requests/_form.html.erb
を持っていると私は追加することによって、私のconfig/routes.rb
内のリソースを含め、部分的に私requests_controller.rb
class RequestsController < ApplicationController
before_action :set_request, only: [:show, :edit, :update, :destroy]
# GET /requests
# GET /requests.json
def index
@requests = Request.all
end
# GET /requests/1
# GET /requests/1.json
def show
end
# GET /requests/new
def new
@request = Request.new
end
# GET /requests/1/edit
def edit
end
# POST /requests
# POST /requests.json
def create
# Create the user from params
@request = Request.new(request_params)
if @email.save
# Deliver the signup email
RequestNotifierMailer.send_email(@request).deliver
flash[:success] = "Thanks! We'll be in touch soon!"
redirect_to :action => 'new'
else
render :action => 'new'
end
end
# PATCH/PUT /requests/1
# PATCH/PUT /requests/1.json
def update
respond_to do |format|
if @request.update(request_params)
format.html { redirect_to @request, notice: 'Request was successfully updated.' }
format.json { render :show, status: :ok, location: @request }
else
format.html { render :edit }
format.json { render json: @request.errors, status: :unprocessable_entity }
end
end
end
# DELETE /requests/1
# DELETE /requests/1.json
def destroy
@request.destroy
respond_to do |format|
format.html { redirect_to requests_url, notice: 'Request was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_request
@request = Request.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def request_params
params.require(:request).permit(:name, :email, :phone, :product, :details)
end
end
の形式があります。 resources :requests
私は」を努力しているstatic_pages/_requestquote.html.erb
にrequests/form
を含むようにG:
<div class="actionsHolder">
<div class="buyHolder">
<h2>Starting from <%= price %></h2>
<h3 id="myBtn">
<a href="#">
Request for Quote
</a>
</h3>
</div>
</div>
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<%= render :partial => "requests/form" %>
</div>
</div>
は、しかし、私はエラーを取得している:
NoMethodError in Products#bigmikepopular113
Showing /Users/beckah/Documents/projects/Envirovacs/app/views/requests/_form.html.erb where line #1 raised:
undefined method `model_name' for #<ActionDispatch::Request:0x007fee89b49040>
Extracted source (around line #1):
1
2
3
4
5
6
<%= form_for(request) do |f| %>
<% if request.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(request.errors.count, "error") %> prohibited this request from being saved:</h2>
<ul>
Products#bigmikepopular113
は、元の部分がconludedされたコントローラの図であるので、本質的に構造が
ありますproducts/bigmikepopular113.html.erb
- >static_pages/_requestquote.html.erb
- >requests/_form.html.erb
埋め込まれた部分を持つことができるかどうか、私は異なったやり方で対応できますか?