Skip to content

Commit

Permalink
Improve methods for routes
Browse files Browse the repository at this point in the history
  • Loading branch information
YOSHIDA Hiroki committed Aug 24, 2014
1 parent a020c33 commit 6c0827a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
10 changes: 0 additions & 10 deletions app/controllers/poteti/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@ module Poteti
class ApplicationController < ActionController::Base
# refs: http://stackoverflow.com/questions/5729476/render-without-layout-when-format-is-js-needs-drying
layout -> (c) { c.request.xhr? ? false : 'poteti/application' }

def default_url_options
{ user_name: (@user || current_user).try(:name) }
end

alias_method :tip_path, :user_tip_path
alias_method :tips_path, :user_tips_path
alias_method :tip_url, :user_tip_url
alias_method :tips_url, :user_tips_url
helper_method :tip_path, :tips_path, :tip_url, :tips_url
end
end
8 changes: 5 additions & 3 deletions app/controllers/poteti/tips_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_dependency 'poteti/application_controller'

module Poteti
class TipsController < ApplicationController
def show
Expand All @@ -12,10 +14,10 @@ def create

respond_to do |format|
if @tip.save
format.html { redirect_to @tip, notice: 'Tip was successfully created.' }
format.js { render status: :created, location: @tip }
format.html { redirect_to [current_user, @tip], notice: 'Tip was successfully created.' }
format.js { render status: :created, location: [current_user, @tip] }
else
format.html { redirect_to tips_path }
format.html { redirect_to user_tips_path }
format.js { render json: @tip.errors, status: :unprocessable_entity }
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/poteti/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_dependency 'poteti/application_controller'

module Poteti
class UsersController < ApplicationController
def show
Expand Down
4 changes: 4 additions & 0 deletions app/models/poteti/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ class User < ActiveRecord::Base
devise(*DEVISE_OPTIONS)

has_many :tips

def to_param
name
end
end
end
4 changes: 2 additions & 2 deletions app/views/poteti/users/show.slim
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
section.tips
.tip.new
- tip = @user.tips.new
= form_for tip, remote: true do |f|
= form_for [@user, tip], remote: true do |f|
p = f.text_field :title, placeholder: tip.class.human_attribute_name(:title)
p = f.text_area :body, placeholder: tip.class.human_attribute_name(:body)
= f.submit

- @tips.each do |tip|
= link_to tip do
= link_to [@user, tip] do
= render 'poteti/tips/show_with_folding', tip: tip

aside
Expand Down

0 comments on commit 6c0827a

Please sign in to comment.