Permalink
Browse files

All page links pointing to correct controllers and pages

  • Loading branch information...
1 parent 07f2d2e commit 9a7a744c46996981a84939859265721e0e2ae66a @KentonWhite committed May 30, 2010
@@ -6,29 +6,33 @@ class LinksController < ApplicationController
def new
@link = @node.links.new
+ @nodes = @maze.nodes.all.collect { |n| [n.title, n.id] }
end
def create
@link = @node.links.new(params[:link])
if @link.save
flash[:notice] = "Successfully created link."
- redirect_to root_url
- else
- render :action => 'new'
+ redirect_to edit_maze_node_path(@maze, @node)
+ else
+ flash[:error] = "Link wasn't created"
+ redirect_to new_maze_node_link_path(@maze, @node)
end
end
def edit
@link = @node.links.find(params[:id])
+ @nodes = @maze.nodes.all.collect { |n| [n.title, n.id] }
end
def update
@link = @node.links.find(params[:id])
if @link.update_attributes(params[:link])
flash[:notice] = "Successfully updated link."
- redirect_to root_url
+ redirect_to edit_maze_node_path(@maze, @node)
else
- render :action => 'edit'
+ flash[:error] = "Link wasn't updated"
+ redirect_to edit_maze_node_link_path(@maze, @node)
end
end
@@ -18,7 +18,7 @@ def create
@maze = current_user.mazes.new(params[:maze])
if @maze.save
flash[:notice] = "Successfully created maze."
- redirect_to @maze
+ redirect_to new_maze_node_path(@maze)
else
render :action => 'new'
end
@@ -9,7 +9,7 @@ def index
def show
@node = @maze.nodes.find(params[:id])
- @links = @node.links.all
+ get_links
end
def new
@@ -20,24 +20,25 @@ def create
@node = @maze.nodes.new(params[:node])
if @node.save
flash[:notice] = "Successfully created node."
- redirect_to [@maze, @node]
+ redirect_to edit_maze_path(@maze)
else
render :action => 'new'
end
end
def edit
@node = @maze.nodes.find(params[:id])
+ get_links
end
def update
- @node = @maze.nodes.find(params[:id])
+ @node = @maze.nodes.find(params[:id])
if @node.update_attributes(params[:node])
flash[:notice] = "Successfully updated node."
- redirect_to [@maze, @node]
else
- render :action => 'edit'
+ flash[:error] = "Node wasn't updated"
end
+ redirect_to edit_maze_path(@maze)
end
def destroy
@@ -47,4 +48,11 @@ def destroy
redirect_to maze_nodes_url @maze
end
+ protected
+
+
+ def get_links
+ @links = @node.links.all
+ end
+
end
@@ -6,7 +6,7 @@
</p>
<p>
<%= f.label :to_node_id %><br />
- <%= f.text_field :to_node_id %>
+ <%= f.select :to_node_id, @nodes %>
</p>
<p><%= f.submit %></p>
<% end %>
@@ -1,4 +1,4 @@
-<% title "Edit Link" %>
+<% title "Edit Link for #{@node.title}" %>
<%= render 'form' %>
@@ -1,4 +1,4 @@
-<% title "New Link" %>
+<% title "New Link for #{@node.title}" %>
<%= render 'form' %>
@@ -1,13 +1,15 @@
<% title "Edit Maze" %>
-<%= render 'form' %>
+<p>
+ <strong>Title:</strong>
+ <p><%= @maze.title %></p>
+</p>
<p>
<strong>Nodes:</strong>
<% @nodes.each do |node| %>
<p>
<%= node.title %>
- <%= link_to "Show", maze_node_path(@maze, node)%> |
<%= link_to "Edit", edit_maze_node_path(@maze, node) %> |
<%= link_to "Destroy", [@maze, node], :confirm => 'Are you sure?', :method => :delete %>
</p>
@@ -16,6 +18,6 @@
</p>
<p>
- <%= link_to "Show", @maze %> |
+ <%= link_to "Create Node", new_maze_node_path(@maze) %> |
<%= link_to "View All", mazes_path %>
</p>
@@ -14,4 +14,4 @@
<% end %>
</table>
-<p><%= link_to "New Maze", new_maze_path %></p>
+<p><%= link_to "Create Maze", new_maze_path %></p>
@@ -1,8 +1,18 @@
<% title "Edit Node" %>
-
-<%= render 'form' %>
+<p>
+ <strong>Title:</strong>
+ <%= @node.title %>
+</p>
+<p>
+ <strong>Content:</strong>
+ <%= @node.content %>
+</p>
<p>
- <%= link_to "Show", [@maze, @node] %> |
- <%= link_to "View All", maze_nodes_path(@maze) %>
+<%= render :partial => 'show_links' %>
</p>
+
+<p>
+ <%= link_to "Add Link", new_maze_node_link_path(@maze, @node) %> |
+ <%= link_to "Back", edit_maze_path(@maze) %>
+</p>
@@ -14,13 +14,13 @@ def test_new
def test_create_invalid
Link.any_instance.stubs(:valid?).returns(false)
post :create, :maze_id => mazes(:one), :node_id => nodes(:one)
- assert_template 'new'
+ assert_redirected_to new_maze_node_link_url(mazes(:one), nodes(:one))
end
def test_create_valid
Link.any_instance.stubs(:valid?).returns(true)
post :create, :maze_id => mazes(:one), :node_id => nodes(:one)
- assert_redirected_to root_url
+ assert_redirected_to edit_maze_node_url(mazes(:one), nodes(:one))
end
def test_edit
@@ -31,13 +31,13 @@ def test_edit
def test_update_invalid
Link.any_instance.stubs(:valid?).returns(false)
put :update, :maze_id => mazes(:one), :node_id => nodes(:one), :id => Link.first
- assert_template 'edit'
+ assert_redirected_to edit_maze_node_link_url(mazes(:one), nodes(:one))
end
def test_update_valid
Link.any_instance.stubs(:valid?).returns(true)
put :update, :maze_id => mazes(:one), :node_id => nodes(:one), :id => Link.first
- assert_redirected_to root_url
+ assert_redirected_to edit_maze_node_url(mazes(:one), nodes(:one))
end
def test_destroy
@@ -30,7 +30,7 @@ def test_create_invalid
def test_create_valid
Maze.any_instance.stubs(:valid?).returns(true)
post :create
- assert_redirected_to maze_url(assigns(:maze))
+ assert_redirected_to new_maze_node_url(assigns(:maze))
end
def test_edit
@@ -30,7 +30,7 @@ def test_create_invalid
def test_create_valid
Node.any_instance.stubs(:valid?).returns(true)
post :create, :maze_id => mazes(:one)
- assert_redirected_to maze_node_url(mazes(:one), assigns(:node))
+ assert_redirected_to edit_maze_url(mazes(:one))
end
def test_edit
@@ -41,13 +41,13 @@ def test_edit
def test_update_invalid
Node.any_instance.stubs(:valid?).returns(false)
put :update, :maze_id => mazes(:one), :id => Node.first
- assert_template 'edit'
+ assert_redirected_to edit_maze_url(mazes(:one))
end
def test_update_valid
Node.any_instance.stubs(:valid?).returns(true)
put :update, :maze_id => mazes(:one), :id => Node.first
- assert_redirected_to maze_node_url(mazes(:one), assigns(:node))
+ assert_redirected_to edit_maze_url(mazes(:one))
end
def test_destroy

0 comments on commit 9a7a744

Please sign in to comment.