diff options
| author | Kir | 2011-11-01 14:18:21 +0400 | 
|---|---|---|
| committer | Kir | 2011-11-01 14:18:21 +0400 | 
| commit | 49e19f446e625ef1fcac1e8890dba0b34b234ec2 (patch) | |
| tree | 8d3a29793d4d43bddba70abcaef071d40277daa0 /app/controllers/discussions_controller.rb | |
| parent | f96948724a0c157f98b952e6bd83da28d06ba1d9 (diff) | |
| download | inboxes-49e19f446e625ef1fcac1e8890dba0b34b234ec2.tar.bz2 | |
Speakers, new readme, dependencies and views generator
Diffstat (limited to 'app/controllers/discussions_controller.rb')
| -rw-r--r-- | app/controllers/discussions_controller.rb | 23 | 
1 files changed, 8 insertions, 15 deletions
| diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb index eb91cfc..cf658b6 100644 --- a/app/controllers/discussions_controller.rb +++ b/app/controllers/discussions_controller.rb @@ -5,23 +5,16 @@ class DiscussionsController < ApplicationController    before_filter :load_and_check_discussion_recipient, :only => [:create, :new]    def index -    # показываем дискуссии юзера, и те куда его присоеденили -    # так как имеем массив дискуссий, его пагинация будет через хак      @discussions = current_user.discussions -     -    respond_to do |format| -      format.html # index.html.erb -      format.json { render :json => @discussions } -    end    end    # GET /discussions/1    # GET /discussions/1.json    def show      @discussion = Discussion.includes(:messages, :speakers).find(params[:id]) -    redirect_to root_url, :notice => t("views.discussions.can_not_participate") unless @discussion.can_participate?(current_user) +    redirect_to discussions_url, :notice => t("views.discussions.can_not_participate") unless @discussion.can_participate?(current_user) -    @discussion.mark_as_read_for(current_user) # сделаем прочтенной для пользователя +    @discussion.mark_as_read_for(current_user)    end    # GET /discussions/new @@ -42,7 +35,6 @@ class DiscussionsController < ApplicationController        m.user = current_user      end -          if @discussion.save        redirect_to @discussion, :notice => t("views.discussions.started")      else @@ -58,17 +50,18 @@ class DiscussionsController < ApplicationController    private    def load_and_check_discussion_recipient +    # initializing model fir new and create actions      @discussion = Discussion.new((params[:discussion] ? params[:discussion] : {})) -    @discussion.recipient_tokens = params[:recipients] if params[:recipients] +    # @discussion.recipient_tokens = params[:recipients] if params[:recipients] # pre-population -    # проверка, существует ли уже дискуссия с этим человеком +    # checking if discussion with this user already exists      if @discussion.recipient_ids && @discussion.recipient_ids.size == 1        user = User.find(@discussion.recipient_ids.first)        discussion = Discussion.find_between_users(current_user, user)        if discussion -        # дискуссия уже существует, добавим в нее написанное сообщение -        @discussion.messages.each do |m| -          Message.create!(:discussion => discussion, :user => current_user, :body => m.body) if m.body +        # it exists, let's add message and redirect current user +        @discussion.messages.each do |message| +          Message.create(:discussion => discussion, :user => current_user, :body => message.body) if message.body          end          # перекидываем на нее          redirect_to discussion_url(discussion), :notice => t("views.discussions.exists", :user => user[Inboxes::config.user_name]) | 
