lundi 30 décembre 2019

Unable to render different form for same Projectsite

I have a project_site model that saves project attributes. I have created a manager_remark model that has a form for each project_site created. Now I have created a model director and I want to render a different form I have created a director model that has an attribute :remark and : status but i am getting error. is it possible to have a different form for the same project_site.

routes.rb

  resources :project_sites do
    resources :manager_remarks
    resources :director_remarks

  end

project_site_controller.rb

  def index
    @project_sites = current_user.project_sites.order("created_at DESC").paginate(page: params[:page], per_page: 10)
  end

  def show
    @manager_remark = ManagerRemark.new
    @manager_remark.project_site_id = @project_site.id
    @director_remarks = DirectorRemark.new
    @director_remarks.project_site_id = @project_site.id

  end

director_remarks_controller.rb

  def create
    @director_remarks = DirectorRemark.new(remark_params)
    @director_remarks.project_site_id = params[:project_site_id]
    @director_remarks.save

    redirect_to project_site_path(@director_remarks.project_site)
  end

  def remark_params
    params.require(:manager_remark).permit(:remark, :status)
  end

director_remark_form.html.erb

<%= form_for [ @project_site, @director_remarks ] do |f| %>
  <div class="row">
    <div class="medium-6 columns">
      <%= f.radio_button :status, true  %>
      <%= f.label :approve %>
      <%= f.radio_button :status, false  %>
      <%= f.label :reject %>
    </div>
    <br>
    <br>
    <div class="medium-6 cloumns">
      <%= f.label :remark %><br/>
      <%= f.text_area :remark %>
    </div>

      </div>
    <div>
      <%= f.submit 'Submit', :class => 'button primary' %>
    </div>

<% end %>

I can render a form for user role manager but I am unable to render a form for user role director for the same project site. Please help.

Aucun commentaire:

Enregistrer un commentaire