Ruby on Rails Thursday, November 28, 2013

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?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/26d6cafc-b4ab-4ebb-8ff5-1a2207b16a2c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment