Skip to content

Commit

Permalink
ajax_repalce
Browse files Browse the repository at this point in the history
  • Loading branch information
mkiselyow committed May 10, 2017
1 parent 9b05898 commit eec43a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
25 changes: 0 additions & 25 deletions app/controllers/static_pages_controller.rb
Expand Up @@ -8,37 +8,12 @@ def index
end

def destroy
@post.destroy
# redirect_to root_path, :notice => 'The Post has been deleted!'
respond_to do |format|
format.html { redirect_to posts_url }
format.js { render :layout => false }
format.json { head :no_content }
end
end

def create
@post = current_user.posts.build(params[:post])
@feed_items = current_user.feed.paginate(page: params[:page])
respond_to do |format|
if @post.save
flash[:success] = "Post created!"
format.html { redirect_to @post }
format.js
format.json { render json: @post, status: :created, location: @post }
else
flash.now[:error] = "your message"
@feed_items = []
render 'static_pages/home'
end
end
end


def show
if signed_in?
@post = current_user.posts.build
@feed_items = current_user.feed.paginate(page: params[:page])
end
end
end
2 changes: 1 addition & 1 deletion app/views/posts/create.js.erb
@@ -1,3 +1,3 @@
$("#add_post").replaceWith("<%= j render(:partial => 'posts/post_added') %>");
$(".posts_count").html("<%= pluralize(current_user.posts.count, 'post') %>");
$("#posts").replaceWith("<%= j render(:partial => 'shared/feed', collection: @feed_items) %>")
$("#posts").replaceWith("<%= j render(:partial => 'feed', collection: @feed_items) %>")
6 changes: 6 additions & 0 deletions config/routes.rb
Expand Up @@ -54,11 +54,17 @@
collection { post :import}
end

resources :users do
resources :posts
end

root to: "static_pages#index"
get "/home" => "static_pages#index"

resources :sessions, only: [:new, :create, :destroy]

match 'index', to: 'static_pages#index', via: [:get, :post]


match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
Expand Down

0 comments on commit eec43a2

Please sign in to comment.