Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use route instead of query string for replies. Eliminate global variable

in leafs controller.
  • Loading branch information...
commit 46372da21b86b895d3f4216dab3e2b4da05e6a65 1 parent bd12b6f
@mcfiredrill authored
View
7 app/controllers/leafs_controller.rb
@@ -1,8 +1,7 @@
class LeafsController < ApplicationController
def new
@leaf = Leaf.new
- @branch = Branch.find(params[:branch])
- $theid = @branch.id
+ @branch = Branch.find(params[:id])
respond_to do |format|
format.html
@@ -10,7 +9,7 @@ def new
end
def create
- @parentbranch = Branch.find($theid)
+ @parentbranch = Branch.find(params[:branch_id])
@leaf = Leaf.new(params[:leaf])
@leaf.branch_id = @parentbranch.id
@@ -25,7 +24,7 @@ def create
format.html { redirect_to new_branch_path }
end
else
- @branch = Branch.find($theid)
+ @branch = Branch.find(params[:branch_id])
format.html { render :action => "new" }
end
end
View
2  app/views/branches/_branch.html.haml
@@ -4,7 +4,7 @@
%div.branch
%div{:class => "firstleaf", :id => "#{f.id}"}
- if !reply_mode?
- %div.replylink=link_to 'Reply', "/leafs/new?branch=#{branch.id}"
+ %div.replylink=link_to 'Reply', "/leafs/new/#{branch.id}"
= render f
- for i in 1..branch.leafs.length-1
%div{:class => "leaf", :id => "#{branch.leafs[i].id}"}
View
2  app/views/branches/new.html.haml
@@ -1,4 +1,4 @@
-= render :partial => "layouts/form", :locals => { :newpost => @branch, :leaf => @leaf }
+= render :partial => "layouts/form", :locals => { :newpost => @branch, :leaf => @leaf, :branch => @branch }
= form_for :branch, :html => { :method => :delete } do |del|
= render :partial => 'cur_page', :locals => { :del => del }
View
1  app/views/layouts/_form.html.haml
@@ -9,6 +9,7 @@
%div.postarea_container
= fields_for leaf do |l|
%div.postarea
+ = hidden_field_tag("branch_id", branch.id)
%table
%tr
%td.fieldlabel Name
View
2  app/views/leafs/new.html.haml
@@ -5,5 +5,5 @@
%div.replyheader Posting mode: Reply
-= render :partial => "layouts/form", :locals => { :newpost => @leaf, :leaf => @leaf }
+= render :partial => "layouts/form", :locals => { :newpost => @leaf, :leaf => @leaf, :branch => @branch }
= render @branch
View
2  config/routes.rb
@@ -3,6 +3,8 @@
resources :branches
+ match 'leafs/new/:id' => 'leafs#new'
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
1  db/schema.rb
@@ -20,7 +20,6 @@
end
create_table "branches", :force => true do |t|
- t.string "name"
t.datetime "last_post_at"
t.datetime "created_at"
t.datetime "updated_at"
Please sign in to comment.
Something went wrong with that request. Please try again.