1
이것은 쉽게 할 수있는 것처럼 보입니다. 기본적으로 Devise를 관리 목적으로 사용하고 있으므로 가입하는 모든 사용자는 자신의 계정에 연결된 제품/그림을 생성 한 다음 해당 제품을 다른 사용자.Form_for with radio_button with database
Class User
rolify
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :role_ids, :as => :admin
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :trades
has_many :figures, :through => :trades
accepts_nested_attributes_for :trades
Class Figure
attr_accessible :image_url, :name, :series, :figure_id
has_many :trades
has_many :users, :through => :trades
accepts_nested_attributes_for :trades
Class Trade
attr_accessible :figure_id, :user_id
belongs_to :user
belongs_to :figure
def new
@trade = Trade.new
end
def create
@trade = current_user.figures.build(params[:trade])
end
무역 여기
<%= form_for(@trade) do |f| %>
<div class="field">
<% Figure.all.each do |figure| %>
# Create a list of figurines radio buttons
<%= f.radio_button :figure_id, figure.id, :checked => (params[:figure_id] == nil ? false : params[:figure_id]) %>
# Link the figures thumbnail to the radio button
<%= f.label :figure_id, image_tag(figure.image_url, :size => "40x58", :alt => figure.name), :value => "#{figure.id}" %>
<% end %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
의 양식 전시회
의 컨트롤러는 여기에{"utf8"=>"✓",
"authenticity_token"=>"lo+RWOLxGhPIP1pmJhk9v+vetO7cGEKGY844egaQ6A0=",
"trade"=>{"figure_id"=>"12"},
"commit"=>"Create Trade"}
내가지고있어 문제의 매개 변수입니다 :에서
알 수없는 공물 : figure_id
왜이 오류가 발생합니까? 내가 제대로 이해하면 대신 Figure
의 Trade
을 (? 당신이 바로, 새로운 무역을 통해 사용자에게 그림을 연결하려는) 구축하면
네, 효과적이었습니다. 와우. – jmorrissette