docbrown/app/controllers/podcasts_controller.rb
Anna Buianova e09e46ec99 Creating podcasts by users (#3730) [deploy]
* Create podcast as a user [WIP]

* Sample css for podcast form

* Nicer podcasts suggesting form

* Validate podcast feed_url

* Validate podcast main_color_hex

* Fix podcasts specs

* Fix form appearance

* Placeholder for podcast main_color_hex

* Provide a link to suggest a podcast

* Add a checkbox and a role for when a podcast is added by an owner

* Prettier checkbox in the podcasts form

* Added creator to podcasts

* Set the podcast creator

* Fix the /pod spec

* Added creator information to the internal podcast page

* Added cta class to the podcasts submit button

* Global notice when a podcast was suggested

Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
2020-01-08 16:14:25 -05:00

34 lines
924 B
Ruby

class PodcastsController < ApplicationController
before_action :authenticate_user!
def new
@podcast = Podcast.new
@podcasts = Podcast.available.order("title asc")
@podcast_index = true
end
def create
@podcast = Podcast.new(podcast_params)
@podcast.creator = current_user
if @podcast.save
current_user.add_role(:podcast_admin, @podcast) if added_by_owner?
flash[:global_notice] = "Podcast suggested"
redirect_to "/pod"
else
@podcasts = Podcast.available.order("title asc")
@podcast_index = true
render :new
end
end
private
def added_by_owner?
params[:i_am_owner].to_i == 1
end
def podcast_params
allowed_params = %i[android_url image itunes_url main_color_hex overcast_url pattern_image slug soundcloud_url twitter_username website_url title feed_url description]
params.require(:podcast).permit(allowed_params)
end
end