Skip to content

Commit fa4067d

Browse files
committed
update and delete are now working for roles.
1 parent ae9c477 commit fa4067d

File tree

8 files changed

+41
-3
lines changed

8 files changed

+41
-3
lines changed

app/controllers/actors_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class ActorsController < ApplicationController
2+
around_filter Neo4j::Rails::Transaction, :only => [:edit, :create, :update, :destroy]
23

34
def index
45
@actors = Actor.all

app/controllers/movies_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class MoviesController < ApplicationController
2+
around_filter Neo4j::Rails::Transaction, :only => [:edit, :create, :update, :destroy]
23

34
def index
45
@movies = Movie.all

app/controllers/roles_controller.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class RolesController < ApplicationController
2+
around_filter Neo4j::Rails::Transaction, :only => [:edit, :create, :update, :destroy]
23

34
def show
45
@role = Role.find(params[:id])
@@ -17,4 +18,28 @@ def create
1718
@role.save
1819
redirect_to role_path(@role.id)
1920
end
21+
22+
def edit
23+
@role = Role.find(params[:id])
24+
@actor = @role.start_node
25+
@movie = @role.end_node
26+
end
27+
28+
def update
29+
@role = Role.find(params[:id])
30+
if @role.update_attributes(params[:role])
31+
redirect_to(@role, :notice => 'Role was successfully updated.')
32+
else
33+
@actor = @role.start_node
34+
@movie = @role.end_node
35+
render :action => "edit"
36+
end
37+
end
38+
39+
def destroy
40+
@role = Role.find(params[:id])
41+
@actor = @role.start_node
42+
@role.destroy
43+
redirect_to actor_path(@actor)
44+
end
2045
end

app/views/movies/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<table>
2020
<% @movie.actors_rels.each do |r| %>
2121
<tr>
22-
<td><%= link_to(sanitize(r.start_node.name), actor_path(r.start_node)) %> as <%= sanitize r.as %></td>
22+
<td><%= link_to r.start_node.name, actor_path(r.start_node) %> as <%= link_to r.as, role_path(r) %></td>
2323
</tr>
2424
<% end %>
2525
</table>

app/views/roles/_form.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<div><%= @actor.name %> acted in <i><%= @movie.title %></i> as...</div>
12
<%= form_for(@role) do |f| %>
23
<% if @role.errors.any? %>
34
<div id="error_explanation">

app/views/roles/edit.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h2>Edit Role</h2>
2+
<%= render "form" %>

app/views/roles/new.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
<h2>New Role</h2>
2-
<div><%= @actor.name %> acted in <i><%= @movie.title %></i> as...</div>
32
<%= render "form" %>

app/views/roles/show.html.erb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
<p id="notice"><%= notice %></p>
2+
13
<h2>Role</h2>
24
<div>
35
<%= link_to @role.start_node.name, actor_path(@role.start_node) %>
4-
acted in
6+
played
7+
<%= @role.as %>
8+
in
59
<i><%= link_to @role.end_node.title, movie_path(@role.end_node) %></i>.
610
</div>
11+
12+
<div style="margin-top: 20px;">
13+
<%= link_to 'Edit', edit_role_path(@role) %> |
14+
<%= link_to 'Destroy', role_path(@role), :confirm => 'Are you sure?', :method => :delete %>
15+
</div>

0 commit comments

Comments
 (0)