未定义的方法`输入' for" NoMethodError in Revisers#new"

时间:2016-05-16 03:17:06

标签: html ruby-on-rails ruby forms controller

我试图让这个表单起作用。 Revisershas_one的关系User

new.html:



<div class="container">

		<%= form_for @reviser, url: new_user_reviser_path(user_id: current_user.id) do |f| %>

		<div class="row">
			<div class="div.col-md-4 select">
			<div class="form-group">
				<label>dsd</label>
				<%= f.input :description %>
			</div>
				
			</div> 
		</div>
             <%= f.submit "Become Adviser", class: "btn btn-large btn-primary" %>
		<% end %>
		</div>
	</div>
&#13;
&#13;
&#13;

错误日志:

Rendered revisers/_form.html.erb (30.8ms)
  Rendered revisers/new.html.erb within layouts/application (31.7ms)
Completed 500 Internal Server Error in 38ms (ActiveRecord: 0.3ms)

ActionView::Template::Error (undefined method `input' for #<ActionView::Helpers::FormBuilder:0x007faf35829f10>):
    11:             <div class="div.col-md-4 select">
    12:             <div class="form-group">
    13:                 <label>dsd</label>
    14:                 <%= f.input :description %>
    15:             </div>
    16:                 
    17:             </div> 
  app/views/revisers/_form.html.erb:14:in `block in _app_views_revisers__form_html_erb___2471522092853631188_70195247159960'
  app/views/revisers/_form.html.erb:8:in `_app_views_revisers__form_html_erb___2471522092853631188_70195247159960'
  app/views/revisers/new.html.erb:1:in `_app_views_revisers_new_html_erb___1451348464463745171_70195280947160'

reviserController:

class RevisersController < ApplicationController

  before_action :set_reviser, only: [:show, :edit, :update]
  before_action :authenticate_user!, except: [:show]

  def index
    @reviser = current_user.reviser
  end

  def show

  end

  def new
    @reviser = current_user.build_reviser(params[:reviser])
    @user = User.find(params[:user_id])
  end

  def create
    @reviser = current_user.reviser.build(reviser_params)

    if @reviser.save
      redirect_to @reviser,notice: "saved...."
    else 
      render :new
    end
  end

  def edit
    set_reviser
  end

  def update
    set_reviser
    if @reviser.update(reviser_params)
      redirect_to @reviser,notice: "updated.."
    else
      render :edit
    end
  end

private 
  def set_reviser
    @reviser = current_user.reviser
  end

  def reviser_params
    params.require(:reviser).permit(:description, :average_start, :average_end, :max_pages, :price_per, :active)
  end
end

1 个答案:

答案 0 :(得分:4)

f.input没有为默认的Rails表单助手定义。您可能会对使用f.input的Formtastic / SimpleForm语法感到困惑。

如果您不使用Simple Form或Formtastic,那么只需使用Rails提供的标准表单帮助方法:http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

<%= f.text_field :description %>