i have 2 models property and property dates. i need to save multiple start date and end date for a property in property dates tables table fields(property_id,start_date_end_date) my model tables
`class Property < ActiveRecord::Base
has_many :property_dates
accepts_nested_attributes_for :property_dates
end`
`class PropertyDate < ActiveRecord::Base
belongs_to :property
end`
class Users::PropertiesController < ApplicationController
before_filter :authenticate_user!
before_action :set_properties, only: [:show, :edit, :update, :destroy]
def index
@properties = Property.where(:user_id=>current_user.id)
end
def list
@properties = Property.all
end
def show
end
def new
@property= Property.new
end
def edit
end
def create
@property = Property.new(properties_params)
respond_to do |format|
if @property.save
format.json { render :index, status: :created, location: @property }
else
format.html { render :new }
format.json { render json: @property.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @property.update(properties_params)
format.json { render :back, status: :ok, location: @property }
else
format.json { render json: @property.errors, status: :unprocessable_entity }
end
end
end
def destroy
@property.destroy
respond_to do |format|
format.html { redirect_to :back, notice: 'Property was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_properties
@property = Property.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def properties_params
params.require(:property).permit(:Space_name,:user_id,:address,:pincode,:image,property_dates_attributes: [ :start_date, :end_date ])
form property form i need to select multiple dates and need to save to property_dates table
my form.html.erb
`<%= simple_nested_form_for ([:users,@property]) do |f| %>
<%= f.fields_for :property_dates do |p| %>
<%= p.text_field :start_date%>
<%= p.text_field :end_date%>
<% end %>
<% end %>`
When i write form it is not visible in my form. Why it is happening like that? Any error in my code. Please help.
Aucun commentaire:
Enregistrer un commentaire