Many to Many table collection_select error -
i trying have rails populate inbetween table. inbetween table is: room_task form using new task form, nested.
here model:
class property < activerecord::base (property parent nest) attr_accessible :brand_id, :name, :user_property_code, :total_rooms, :property_addresses_attributes belongs_to :brand has_many :rooms has_many :nonrooms end class room < activerecord::base (room) attr_accessible :number, :out_of_order, :property_id, :room_type_id, :taskable_id belongs_to :room_type belongs_to :property has_many :room_tasks has_many :tasks, through: :room_tasks accepts_nested_attributes_for :tasks accepts_nested_attributes_for :room_tasks #add_index :room, :property_id end class room < activerecord::base (task) attr_accessible :number, :out_of_order, :property_id, :room_type_id, :taskable_id belongs_to :room_type belongs_to :property has_many :room_tasks has_many :tasks, through: :room_tasks accepts_nested_attributes_for :tasks accepts_nested_attributes_for :room_tasks #add_index :room, :property_id end class roomtask < activerecord::base (in between table) attr_accessible :room_id, :task_id has_one :room has_one :task belongs_to :room # foreign key - room id belongs_to :task # foreign key - task id end
controller (task - want create new task , required relationship in inbetween table)
class taskscontroller < applicationcontroller before_filter :find_property def find_property @property = property.find(params[:property_id]) @room = @property.rooms end # /tasks # /tasks.json def index @tasks = task.all respond_to |format| format.html # index.html.erb format.json { render json: @tasks } end end # /tasks/1 # /tasks/1.json def show @task = task.find(params[:id]) respond_to |format| format.html # show.html.erb format.json { render json: @task } end end # /tasks/new # /tasks/new.json def new @task = task.new respond_to |format| format.html # new.html.erb format.json { render json: @task } end end # /tasks/1/edit def edit @task = task.find(params[:id]) end # post /tasks # post /tasks.json def create @task = task.new(params[:task]) @task.time_assigned = time.now respond_to |format| if @task.save format.html { redirect_to property_tasks_path(@property), notice: 'task created.' } format.json { render json: @task, status: :created, location: @task } else format.html { render action: "new" } format.json { render json: @task.errors, status: :unprocessable_entity } end end end # put /tasks/1 # put /tasks/1.json def update @task = task.find(params[:id]) respond_to |format| if @task.update_attributes(params[:task]) format.html { redirect_to @task, notice: 'task updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @task.errors, status: :unprocessable_entity } end end end # delete /tasks/1 # delete /tasks/1.json def destroy @task = task.find(params[:id]) @task.destroy respond_to |format| format.html { redirect_to tasks_url } format.json { head :no_content } end end end
form (using collection select (purpose select room of property task tied , populate in inbetween table)
<%= form_for([@property, @task]) |f| %> <% if @task.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@task.errors.count, "error") %> prohibited task being saved:</h2> <ul> <% @task.errors.full_messages.each |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div> <%= fields_for(:room_task) |t| %> <%= collection_select(:room_task, :room_id, @room, :id, :number) %> #without t. works not assign <% end %> <%= @room %> #debug collection pull - <div class="actions"> <%= f.submit %> </div> <% end %>
so need on ensuring inbetween table populated when selecting room. when f. or t. prefixed collection_select, rails throws errors. extremely confused. appreciated, please let me know if additional information needed.
receiving error when adding f. or t.
undefined method `merge' :number:symbol
displays , works fine without f. or t. not populate table.
Comments
Post a Comment