Skip to content

Commit

Permalink
Create route for users/:u/series/:s/figures/:f - #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
seiza committed Jun 3, 2012
1 parent 40850cb commit 0aebbcb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
13 changes: 11 additions & 2 deletions app/controllers/user_figures_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
class UserFiguresController < ApplicationController

def user_figure_by_code_or_id(params)
id = params[:id]
figure_code = params[:figure_code]
return UserFigure.find(params[:id]) if id
return UserFigure.find_by_figure_code( params[:figure_code] ) if figure_code
return UserFigure.find_by_figure_code( "#{params[:series_index]}-#{params[:figure_index]}" )
end

# GET /user_figures
# GET /user_figures.json
def index
Expand All @@ -13,7 +22,7 @@ def index
# GET /user_figures/1
# GET /user_figures/1.json
def show
@user_figure = UserFigure.find(params[:id])
@user_figure = self.user_figure_by_code_or_id(params)

respond_to do |format|
format.html # show.html.erb
Expand All @@ -34,7 +43,7 @@ def new

# GET /user_figures/1/edit
def edit
@user_figure = UserFigure.find(params[:id])
@user_figure = self.user_figure_by_code_or_id(params)
end

# POST /user_figures
Expand Down
2 changes: 1 addition & 1 deletion app/views/user_figures/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
<div class="field">
<%= f.label :figure_code %><br />
<%= f.number_field :figure_code %>
<%= f.text_field :figure_code %>
</div>
<div class="field">
<%= f.label :count %><br />
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<table>
<tr>
<th>ID</th>
<th>Login</th>
<th>Password</th>
<th>Firstname</th>
Expand All @@ -17,6 +18,7 @@

<% @users.each do |user| %>
<tr>
<td><%= user.id %></td>
<td><%= user.login %></td>
<td><%= user.password %></td>
<td><%= user.firstName %></td>
Expand Down
23 changes: 21 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
Legomni::Application.routes.draw do

# match ':controller(/:action(/:id))'
# match ':controller/:action/:id/:user_id'

resources :devices

resources :user_figures

resources :figures

resources :series
resources :series do
resources :figures
end

# /users/1/figures/3
# match "/users/:user_id/figures/:figure_code" => redirect("%{scope}_authenticate/create")
match "users/:user_id/series/:series_index/figures/:figure_index" => redirect("/user_figures/show/%{user_id}/%{series_index}/%{figure_index}")
match "users/:user_id/figures/:figure_code" => redirect("/user_figures/show/%{user_id}/%{figure_code}")
resources :users do
resources :user_figures
resources :devices

# get 'preview', :on => :member
# get 'search', :on => :collection
end

resources :users
match ":controller/:action/:user_id/:figure_code"
match ":controller/:action/:user_id/:series_index/:figure_index"

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down

0 comments on commit 0aebbcb

Please sign in to comment.