<commit_before>class CommunitiesController < ApplicationController
  respond_to :html, :xml, :json, :js

  # GET /communities
  # GET /communities.json
  def index
    @communities = Community.getSearch(params)
    respond_with(@communities)
  end

  # GET /communities/1
  # GET /communities/1.json
  def show
    @community = Community.find(params[:id])
    @rcommunities = Community.relatedCommunities(params[:id])
    @posts = Post.getCommunityPosts(params)
    respond_with(@community)
  end

  # GET /communities/new
  # GET /communities/new.json
  def new
    @community = Community.new
    respond_with(@community)
  end

  # GET /communities/1/edit
  def edit
    @community = current_user.own_communities.find(params[:id])
  end

  # POST /communities
  # POST /communities.json
  def create
    @community = Community.new(create_params)
    @community[:owner_id] = current_user.id
    afterSave(@community) if @community.save
    respond_with(@community)
  end

  # PUT /communities/1
  # PUT /communities/1.json
  def update
    @community = current_user.own_communities.find(params[:id])
    flash[:notice] = 'Community was successfully updated.' if @community.update_attributes(update_params)
    respond_with(@community)
  end

  private
  def afterSave(community)
    flash[:notice] = 'Community was successfully created.' 
    CommunityTopic.create(topic_id:Topic.getFirstTopic.id, community_id:community.id)
  end
  
  private
  def create_params
    params.require(:community).permit(:name, :description, :visible, :photo)
  end
  
  private
  def update_params
    params.require(:community).permit(:name, :description, :visible, :photo)
  end

end<commit_msg>fix create action in communities controller<commit_after>class CommunitiesController < ApplicationController
  respond_to :html, :xml, :json, :js

  # GET /communities
  # GET /communities.json
  def index
    @communities = Community.getSearch(params)
    respond_with(@communities)
  end

  # GET /communities/1
  # GET /communities/1.json
  def show
    @community = Community.find(params[:id])
    @rcommunities = Community.relatedCommunities(params[:id])
    @posts = Post.getCommunityPosts(params)
    respond_with(@community)
  end

  # GET /communities/new
  # GET /communities/new.json
  def new
    @community = Community.new
    respond_with(@community)
  end

  # GET /communities/1/edit
  def edit
    @community = current_user.own_communities.find(params[:id])
  end

  # POST /communities
  # POST /communities.json
  def create
    @community = Community.new(create_params)
    @community[:owner_id] = current_user.id
    afterSave(@community) if createActionAvailableTime > 30.seconds and @community.save
    respond_with(@community)
  end

  # PUT /communities/1
  # PUT /communities/1.json
  def update
    @community = current_user.own_communities.find(params[:id])
    flash[:notice] = 'Community was successfully updated.' if @community.update_attributes(update_params)
    respond_with(@community)
  end

  private
  def afterSave(community)
    flash[:notice] = 'Community was successfully created.' 
    CommunityTopic.create(topic_id:Topic.getFirstTopic.id, community_id:community.id)
  end
  
  private
  def create_params
    params.require(:community).permit(:name, :description, :visible, :photo)
  end
  
  private
  def update_params
    params.require(:community).permit(:name, :description, :visible, :photo)
  end
  
  private
  def createActionAvailableTime
    Time.now - if current_user.own_communities.last.blank?
      Time.now - 1.minute
    else
      current_user.own_communities.last.created_at
    end
  end
end
{'fraction_non_alphanumeric': 0.1034103410341034, 'fraction_numerical': 0.0035753575357535755, 'mean_word_length': 3.8753351206434314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5383163', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1113, 'n_words': 237}