mardi 31 juillet 2018

To display the content only after clicking publish button in Ruby on rails

I have a course module where once created it displays in the front end. I want to add a publish and unpublish button for that. Where only when publish button is clicked it should show the details in the front end.

So for that i added the column in db.

create_table "courses", force: :cascade do |t|
  t.boolean "publish"
  t.boolean "unpublish"
  t.index ["slug"], name: "index_courses_on_slug", unique: true
 end

routes:

resources :courses do
  collection do
    delete 'destroy_multiple'
  end
  member do
    post :copy
    get :publish
    get :unpublish
  end
end

and in course_controller i defined an action

def publish
 publish_course = @course.dup
 publish_course.title = "Copied from:#{@course.id} #{@course.title}"
 respond_to do |format|
   if clone_course.save
     format.html { redirect_to publish_course, notice: "Course was successfully published from #{@course.id}: #{@course.title}." }
     format.json { render :show, status: :created, location: @publish_course }
   else
     format.html {  redirect_to courses_path, alert: "Please try again. Something went wrong.." }
     format.json { render json: publish_course.errors, status: :unprocessable_entity }
   end
  end
end

I need to wire it up with the frontend now. How to display this? Can anyone help?

Aucun commentaire:

Enregistrer un commentaire