From de948d7692c06fcce1e7a5da178262a05ea90b72 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 30 Oct 2013 01:56:23 +0100 Subject: [PATCH] fix and cleanup routing (closes foodcoops#190) --- app/controllers/orders_controller.rb | 15 +++++++++------ app/views/articles/_destroy_active_article.haml | 2 +- app/views/home/_start_nav.haml | 2 +- app/views/home/profile.html.haml | 2 +- app/views/login/forgot_password.html.haml | 2 +- app/views/login/new_password.html.haml | 2 +- app/views/orders/show.html.haml | 2 +- app/views/tasks/_archive_tasks.html.haml | 2 +- config/routes.rb | 10 +++++----- 9 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index d52ae698..578327f1 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -48,6 +48,9 @@ class OrdersController < ApplicationController end send_data pdf.to_pdf, filename: pdf.filename, type: 'application/pdf' end + format.text do + send_data text_fax_template, filename: @order.name+'.txt', type: 'text/plain' + end end end @@ -101,12 +104,14 @@ class OrdersController < ApplicationController rescue => error redirect_to orders_url, alert: I18n.t('errors.general_msg', :msg => error.message) end + + protected # Renders the fax-text-file # e.g. for easier use with online-fax-software, which don't accept pdf-files + # TODO move to text template def text_fax_template - order = Order.find(params[:id]) - supplier = order.supplier + supplier = @order.supplier contact = FoodsoftConfig[:contact].symbolize_keys text = I18n.t('orders.fax.heading', :name => FoodsoftConfig[:name]) text += "\n#{Supplier.human_attribute_name(:customer_number)}: #{supplier.customer_number}" unless supplier.customer_number.blank? @@ -117,15 +122,13 @@ class OrdersController < ApplicationController text += "****** " + I18n.t('orders.fax.articles') + "\n\n" text += I18n.t('orders.fax.number') + " " + I18n.t('orders.fax.amount') + " " + I18n.t('orders.fax.name') + "\n" # now display all ordered articles - order.order_articles.ordered.all(:include => [:article, :article_price]).each do |oa| + @order.order_articles.ordered.all(:include => [:article, :article_price]).each do |oa| number = oa.article.order_number (8 - number.size).times { number += " " } quantity = oa.units_to_order.to_i.to_s quantity = " " + quantity if quantity.size < 2 text += "#{number} #{quantity} #{oa.article.name}\n" end - send_data text, - :type => 'text/plain; charset=utf-8; header=present', - :disposition => "attachment; filename=#{order.name}" + text end end diff --git a/app/views/articles/_destroy_active_article.haml b/app/views/articles/_destroy_active_article.haml index 73c59e1c..90dcfae2 100644 --- a/app/views/articles/_destroy_active_article.haml +++ b/app/views/articles/_destroy_active_article.haml @@ -1,3 +1,3 @@ %tr.edit_inline{:id=> "edit_"+@article.id.to_s} %td{:colspan=>"10"} - = t('.note', article: h(@article.name), drop_link: link_to(t('.drop'), :controller => 'orders', :action => 'edit', :id => @order)).html_safe + = t('.note', article: h(@article.name), drop_link: link_to(t('.drop'), edit_order_path(@order))).html_safe diff --git a/app/views/home/_start_nav.haml b/app/views/home/_start_nav.haml index 4f7f1b5c..346aa67a 100644 --- a/app/views/home/_start_nav.haml +++ b/app/views/home/_start_nav.haml @@ -4,7 +4,7 @@ %li.nav-header= t '.foodcoop' %li= link_to t('.members'), foodcoop_users_path %li= link_to t('.tasks'), user_tasks_path - %li= link_to t('.write_message'), :controller => "messages", :action => "new" + %li= link_to t('.write_message'), new_message_path - has_ordergroup = !@current_user.ordergroup.nil? - has_orders_role = @current_user.role_orders? diff --git a/app/views/home/profile.html.haml b/app/views/home/profile.html.haml index d462995a..6a54fce6 100644 --- a/app/views/home/profile.html.haml +++ b/app/views/home/profile.html.haml @@ -5,7 +5,7 @@ %h3 = h(t('.user.title', user: @current_user.nick)) %small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on) - = simple_form_for(@current_user, :url => { :action => 'update_profile'}) do |f| + = simple_form_for(@current_user, :url => update_profile_path) do |f| = render :partial => 'shared/user_form_fields', :locals => {:f => f} .form-actions = submit_tag t('ui.save'), class: 'btn' diff --git a/app/views/login/forgot_password.html.haml b/app/views/login/forgot_password.html.haml index 568ac258..c299f0ae 100644 --- a/app/views/login/forgot_password.html.haml +++ b/app/views/login/forgot_password.html.haml @@ -1,6 +1,6 @@ - title t('.title') = t('.body').html_safe -= simple_form_for User.new, url: {action: 'reset_password'} do |form| += simple_form_for User.new, url: reset_password_path do |form| = form.input :email .form-actions = form.submit t('.submit'), class: 'btn' diff --git a/app/views/login/new_password.html.haml b/app/views/login/new_password.html.haml index d3f2c58c..ea928051 100644 --- a/app/views/login/new_password.html.haml +++ b/app/views/login/new_password.html.haml @@ -1,6 +1,6 @@ - title t('.title') = t('.body', user: h(@user.nick)).html_safe -= simple_form_for @user, :url => {:action => 'update_password', :id => @user.id, :token => @user.reset_password_token} do |form| += simple_form_for @user, :url => update_password_path(@user.id, :token => @user.reset_password_token) do |form| = form.input :password = form.input :password_confirmation .form-actions diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index 0e9a3926..82d43cc2 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -50,7 +50,7 @@ %li= order_pdf(@order, :articles, t('.download.article_pdf')) %li= order_pdf(@order, :matrix, t('.download.matrix_pdf')) %li= order_pdf(@order, :fax, t('.download.fax_pdf')) - %li= link_to t('.download.fax_txt'), {action: 'text_fax_template', id: @order }, {title: t('.download.download_file')} + %li= link_to t('.download.fax_txt'), order_path(@order, format: :txt), {title: t('.download.download_file')} %section#articles_table = render 'articles', order: @order diff --git a/app/views/tasks/_archive_tasks.html.haml b/app/views/tasks/_archive_tasks.html.haml index 46250ddd..9ece4d05 100644 --- a/app/views/tasks/_archive_tasks.html.haml +++ b/app/views/tasks/_archive_tasks.html.haml @@ -13,5 +13,5 @@ - @tasks.each do |task| %tr %td= task.due_date unless task.due_date.nil? - %td= link_to t('.task_format', name: task.name, duration: task.duration), :controller => "tasks", :action => "show", :id => task + %td= link_to t('.task_format', name: task.name, duration: task.duration), task_path(task) %td= task_assignments task diff --git a/config/routes.rb b/config/routes.rb index e3565686..655a1038 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,14 +18,17 @@ Foodsoft::Application.routes.draw do match '/login' => 'sessions#new', :as => 'login' match '/logout' => 'sessions#destroy', :as => 'logout' - get '/login/forgot_password' => 'login#forgot_password', as: :forgot_password - get '/login/new_password' => 'login#new_password', as: :new_password + get '/login/forgot_password' => 'login#forgot_password', as: :forgot_password + post '/login/reset_password' => 'login#reset_password', as: :reset_password + get '/login/new_password' => 'login#new_password', as: :new_password + get '/login/update_password' => 'login#update_password', as: :update_password match '/login/accept_invitation/:token' => 'login#accept_invitation', as: :accept_invitation resources :sessions, :only => [:new, :create, :destroy] ########### User specific match '/home/profile' => 'home#profile', :as => 'my_profile' + put '/home/update_profile' => 'home#update_profile', :as => 'update_profile' match '/home/ordergroup' => 'home#ordergroup', :as => 'my_ordergroup' match '/home/cancel_membership' => 'home#cancel_membership', :as => 'cancel_membership' @@ -181,8 +184,5 @@ Foodsoft::Application.routes.draw do resources :users, :only => [:index] - # TODO: This is very error prone. Better deactivate this catch all route - match ':controller(/:action(/:id))(.:format)' - end # End of /:foodcoop scope end