无法在rails上的ruby中添加新的轮询选项

时间:2017-04-25 11:01:19

标签: ruby-on-rails ruby

我一直在研究这个网络应用程序,现在我遇到了这个我尽我所能,但无法理解这里有什么问题 请帮助
当我点击添加新民意调查时我收到错误消息

**

NoMethodError in Polls#new
Showing /home/cassada/Sites/cs49/app/views/polls/_form.html.erb where line #17 raised:
undefined method `object' for :f:Symbol
Did you mean?  object_id
Extracted source (around line #17):
         16             <div class="links">
         17    <%= link_to_add_association 'add option', :f, :vote_options %>
         18   </div>
         19   </div>
         20  </div>
Trace of template inclusion: app/views/polls/new.html.erb
Rails.root: /home/cassada/Sites/cs49
Application Trace | Framework Trace | Full Trace
app/views/polls/_form.html.erb:17:in `block in _app_views_polls__form_html_erb___3284567334421898573_69867286087680'
app/views/polls/_form.html.erb:1:in `_app_views_polls__form_html_erb___3284567334421898573_69867286087680'
app/views/polls/new.html.erb:3:in `_app_views_polls_new_html_erb___1883683102533192410_69867286238480'
Request
Parameters:
None
Toggle session dump
Toggle env dump
[screenshot][1]
 Extracted source (around line #2):

      <div class="links">
        **<%= link_to_add_association 'add option', :f, :vote_options %>**
      </div>
    </div>
  </div>

**

我究竟需要做些什么来解决这个问题 请帮忙

**new.html.erb**
 <% content_for(:page_header) {"Create a new poll"} %>
  render 'form' %>

form.html.erb

<%= form_for @poll do |f| %>
<%= render 'shared/errors', object: @poll %>

<div class="form-group">
<%= f.label :topic %>
<%= f.text_area :topic, rows: 3, required: true, class: 'form-control' %>
</div>

<div class="panel panel-default">
<div class="panel-heading">Options</div>
<div class="panel-body">
 <%= f.fields_for :vote_options do |options_form| %>
    <%= render 'vote_option_fields', f: options_form %>
  <% end %>

  <div class="links">
    <%= link_to_add_association 'add option', f, :vote_options %>
   </div>
   </div>
   </div>

   <%= recaptcha_tags %>

   <%= f.submit 'Create', class: 'btn btn-primary btn-lg' %>
   <% end %>

民意调查控制器

class PollsController < ApplicationController
 def index
    @polls = Poll.all
  end

  def new
    @poll = Poll.new
  end

  def create
    @poll = Poll.new(poll_params)
    if @poll.save
      flash[:success] = 'Poll was created!'
      redirect_to polls_path
    else
      render 'new'
    end
  end
def poll_params
  params.require(:poll).permit(:topic, vote_options_attributes: [:id, :title, :_destroy])
end
def edit
  @poll = Poll.find_by_id(params[:id])
end

def update
  @poll = Poll.find_by_id(params[:id])
  if @poll.update_attributes(poll_params)
    flash[:success] = 'Poll was updated!'
    redirect_to polls_path
  else
    render 'edit'
  end
end

def destroy
  @poll = Poll.find_by_id(params[:id])
  if @poll.destroy
    flash[:success] = 'Poll was destroyed!'
  else
    flash[:warning] = 'Error destroying poll...'
  end
  redirect_to polls_path
end
def show
  @poll = Poll.find_by_id(params[:id])
end
def show
  @poll = Poll.includes(:vote_options).find_by_id(params[:id])
end
  private

  def poll_params
    params.require(:poll).permit(:topic)
  end
  end

0 个答案:

没有答案