rails how to make tasks

15 views
Skip to first unread message

Adil Abdugaliyev

unread,
Nov 28, 2013, 6:04:24 PM11/28/13
to rubyonra...@googlegroups.com

In my project i want to make tasks like in taskrabbit.com, that user could create task and another user could respond on it. And the user who created task could choose candidates and change status to "accomplished" my models:

class Post < ActiveRecord::Base
    belongs_to :user
    belongs_to :category
    has_many :responces
end

class Responce < ActiveRecord::Base
    belongs_to :user
    belongs_to :post
    default_scope -> { order('created_at DESC') }
end

my posts controller

class PostsController < ApplicationController

load_and_authorize_resource

    def new
        @category = Category.find(params[:category_id])
        @post = @category.posts.new(category_id:params[:category_id])
    end

    def index
        @category = Category.find(params[:category_id])
        @posts = Post.all
    end

    def create
        @post =  current_user.posts.build(post_params)
        @category = Category.find(params[:category_id])


    if @post.save
      flash[:success] = "Поздравляем Ваше задание опубликованно"
      redirect_to post_path @post
    else
    render 'new'
  end
    end

    def update
        @post =  current_user.posts.build(post_params)
        @category = Category.find(params[:category_id])
    end

    def show
        @post = Post.find(params[:id])
        #@category = Category.find(params[:category_id])
        @feed_items = @post.responces.paginate(page: params[:page])
    end

    def feed
        Responce.where("post_id = ?", id)
    end

    def destroy
        @post.responces.destroy
        redirect_to post_path @post
    end

    private
  def post_params
    params.require(:post).permit(:destroy, :name, :content, :date, :time, :category_id, :price, :adress1, :adress2)
  end

end

my view

<%= link_to 'Choose candidate', feed_item,
                                    method: :update,
                            data: { confirm: 'Are you sure?' } %>
</li>

and my responce controller

class ResponcesController < ApplicationController

    def new
        @post = Post.find(params[:post_id])
        @responce = @post.responces.new(post_id:params[:post_id])
        @responce.user = current_user
    end

    def create
        @post = Post.find(params[:post_id])
        @responce = @post.responces.build(responce_params)
        @responce.user = current_user
    if @responce.save
      flash[:success] = "Вы откликнулись на задание"
      redirect_to post_path @post
    else
    render 'new'
  end
    end

    def show
    end

    def destroy
        @responce = Responce.find(params[:id])
        @responce.destroy
        redirect_to posts_path @post
    end

    private

    def responce_params
        params.require(:responce).permit(:price, :comment, :post_id)
    end
end

Can you help me out with that, how I can make it done. Is there any gem or articles about it?

Reply all
Reply to author
Forward
0 new messages