How to modify the redmine mailer templates? - redmine

I'm trying to strip posted messages from forum and the issues. The wiki doesn't send such information by default. The trouble is, that data entered in the body of forum posts or issues might be sensitive and I don't want it flying around the internet unencrypted. We can tolerate (and in fact want) some data being sent. For instance the title of a forum topic or the issue meta-fields to be sent. But the free-form text should be held back.
I found the templates in app/views/mailer but having extremely little knowledge of ruby I find myself unable to modify the issue template. The forum message template was straightforward to change, but this:
<% for detail in #journal.details -%>
<%= show_detail(detail, true) %>
<% end -%>
<%= #journal.notes if #journal.notes? %>
----------------------------------------
<%= render :partial => "issue_text_plain", :locals => { :issue => #issue, :issue_url => #issue_url } %>
is quite unintelligible to me.
Is there a documentation of how the templates work or which fields are available?

It was surprisingly easy to remove the content while keeping the data I wanted. Here's the patch I went with for future reference.
diff -u mailer.orig/issue_add.text.plain.rhtml mailer/issue_add.text.plain.rhtml
--- mailer.orig/issue_add.text.plain.rhtml 2014-11-12 22:13:17.024224309 +0100
+++ mailer/issue_add.text.plain.rhtml 2014-11-12 23:22:57.634311578 +0100
## -1,4 +1 ##
<%= l(:text_issue_added, :id => "##{#issue.id}", :author => #issue.author) %>
-
-----------------------------------------
-<%= render :partial => "issue_text_plain", :locals => { :issue => #issue, :issue_url => #issue_url } %>
diff -u mailer.orig/issue_edit.text.plain.rhtml mailer/issue_edit.text.plain.rhtml
--- mailer.orig/issue_edit.text.plain.rhtml 2014-11-12 22:13:17.024224309 +0100
+++ mailer/issue_edit.text.plain.rhtml 2014-11-12 23:21:06.974188526 +0100
## -3,7 +3,3 ##
<% for detail in #journal.details -%>
<%= show_detail(detail, true) %>
<% end -%>
-
-<%= #journal.notes if #journal.notes? %>
-----------------------------------------
-<%= render :partial => "issue_text_plain", :locals => { :issue => #issue, :issue_url => #issue_url } %>
diff -u mailer.orig/message_posted.text.plain.rhtml mailer/message_posted.text.plain.rhtml
--- mailer.orig/message_posted.text.plain.rhtml 2014-11-12 22:13:17.024224309 +0100
+++ mailer/message_posted.text.plain.rhtml 2014-11-12 23:20:51.057200772 +0100
## -1,4 +1,2 ##
<%= #message_url %>
<%= #message.author %>
-
-<%= #message.content %>
It's a really stupid 'fix' as it basically just removes lines, but it appears to work.

Related

No route matches [POST] "/basic_pages/basic_pages/home"

So I would simply like to post to my root. My problem is that if I try to do it the second time (first time works fine) I am posting /basic_pages/basic_pages/home instead of /basic_pages/home. Why does that happen and how do I fix this?
home.html.erb:
<h1>BasicPages#home</h1>
<p>Find me in app/views/basic_pages/home.html.erb</p>
<%= form_tag ('basic_pages/home') do %>
<%= text_field_tag :my_input %>
<%= submit_tag "Send input" %>
<% end %>
routes.rb
Rails.application.routes.draw do
root 'basic_pages#home'
post 'basic_pages/home'
get 'about' => 'basic_pages#about'
end
Hope this provides all the information necessary.
Instead of using form_tag ('basic_pages/home') use form_tag ('/basic_pages/home'). When you have posted the url is getting changed to /basic_pages/home, and then the form is again posting to /basic_pages/basic_pages/home, because of the relative path given to the form.
Try this
Rails.application.routes.draw do
post '/' => "basic_pages#home", as: "root"
get 'about' => 'basic_pages#about'
end
home.html.erb:
<%= form_tag ('/') do %>
<%= text_field_tag :my_input %>
<%= submit_tag "Send input" %>
<% end %>

Rails 4, Capybara: form_tag produces nil params hash. Why?

Rails 4: While running a feature spec with Capybara, my params hash is nil.
What am I doing wrong here?
# app/views/comics/index.html.erb
<%= form_tag subscriptions_subscribe_path do %>
<%= label_tag :email %>
<%= text_field_tag :email, params[:email]%>
<%= submit_tag 'Submit'%>
<% end %>
# spec/features/subscribe_feature_spec.rb
require 'rails_helper'
require 'pry'
feature 'subscribe to email list' do
scenario 'success' do
visitor_email = 'Monkey#Biz.com'
visit '/'
fill_in :email, with: visitor_email
click_on 'Submit'
# ...balance omitted...
end
end
# app/controllers/subscriptions_controller.rb
class SubscriptionsController < ApplicationController
def subscribe
binding.pry
# params = nil ... WHY?
# params[:email] => undefined method `email' for nil:NilClass
# ...balance omitted...
end
end
I've got a bonehead error somewhere in the code above.
My view contains only a single instance of the word "Submit", so Capybara is not clicking the wrong link.
logs
$ tail -f log/test.log
Started GET "/" for 127.0.0.1 at 2016-03-19 15:01:07 -0700
Processing by ComicsController#index as HTML
Comic Load (0.3ms) SELECT "comics".* FROM "comics"
Rendered comics/index.html.erb within layouts/application (12.4ms)
Rendered shared/_navlinks.html.erb (1.4ms)
Rendered shared/_navlinks.html.erb (0.1ms)
Completed 200 OK in 349ms (Views: 348.6ms | ActiveRecord: 0.3ms)
Started POST "/subscriptions/subscribe" for 127.0.0.1 at 2016-03-19 15:01:08 -0700
Processing by SubscriptionsController#subscribe as HTML
Parameters: {"utf8"=>"✓", "email"=>"Monkey#Biz.com", "commit"=>"Submit"}

Rails 4 gem rails4-autocomplete 1 letter suggestions

I am using gem rails-jquery-autocomplete, but It shows suggestions only after 2 letters, is there a possibility to display suggestions for 1-letter long searching?
Yes there is! Just add 'min-length' => 1 in your search form like:
<%= form_tag terms_path, method: 'get' do %>
<%= autocomplete_field_tag :search, params[:search], autocomplete_term_phrase_terms_path, 'min-length' => 1 %>
<%= submit_tag "Search" %>
<% end %>

Rails: param is missing or the value is empty because param appearing as "#<Edge:0xb2535b8>"

I'm using form for and the name of the form in the controller is appearing as "#", but I expect it to appear as :edge.
Here's my controller:
def new
#some_stuff
#edge = Edge.new
#some_stuff
end
def create
#edge = Edge.new(edge_params)
#edge.save
end
def edge_params
params.require(:edge).permit(:location_1_id, :location_2_id)
end
View:
<%= form_for( :edge, :url => {:action => 'create'}) do |f| %>
<ul>
<li>
<%= f.label :location_1_id %>
<%= collection_select(#edge, :location_1_id, #location, :id, :record_as_string) %>
</li>
<%= submit_tag(t(:create_edge)) %>
</ul>
<% end %>
Param req:
{"utf8"=>"✓", "authenticity_token"=>"blah",
"#"=>{"location_1_id"=>"91", "location_2_id"=>"92"},
"commit"=>"Create Edge", "action"=>"create",
"controller"=>"admin/edges", "floor_map_floor_id"=>"1"}
So the name of the parameter should be :edge but it's an object that I can't access.
Can anybody tell me what I'm missing?
Any help is appreciated.
You should be using the form block on your collection set like so
<%= f.collection_select(:location_1_id, #location, :id, :record_as_string) %>
(notice that you are calling the collection_select on the block variable f, and NOT passing in the #edge as the first argument).
In addition, because you are creating the object in new (#edge = Edge.new), you should just be using in your form, like so
<%= form_for( #edge, :url => {:action => 'create'}) do |f| %>
(although using :edge wasn't the cause of your problems, I suspect it was because you were using :edge and #edge in the same form. You need to be consistent, use one or the other)

Indicate that an uploaded file is present in edit form -- paperclip

In my current solution, I am able to put a checkbox in the edit form so that users can delete attachment. However, there is no indication for the user that a file has been uploaded, the name of that file, etc. so that he can decide whether to delete.
Right now the form look like this. The first material is an existing one, the next 3 are due to
def edit
#post = Post.find(params[:id])
3.times { #post.post_materials.new }
end
As you can see, it's very hard to distinguish between them. Ideally, I want the first material file name to appear somehow.
<%= form_for #post, :html => { :multipart => true } do |f| %>
<%= f.label :title %>
<%= f.text_field :title %>
Materials:
<ul>
<%= f.fields_for :materials, :html => { :multipart => true } do |materials_form| %>
<li>
<%= materials_form.label :asset %>
<%= materials_form.file_field :asset %>
<%= materials_form.label :_destroy, class: "checkbox inline" do %>
Remove attachment <%= materials_form.check_box :_destroy %>
<% end %>
</li>
<% end %>
</ul>
<%= f.submit "Submit", class: "btn btn-large" %>
<% end %>
Running paperclip's generator creates a migration to add 4 attributes on your model, as you can see here. These attributes are:
<attachment>_file_name
<attachment>_file_size
<attachment>_content_type
<attachment>_updated_at
So, If you ran the generator this way: rails generate paperclip post_material asset, on your PostMaterial model, you will have these attributes:
asset_file_name
asset_file_size
asset_content_type
asset_updated_at
Then, on your code you can do something like this:
if materials_form.object.asset.exists? #object represents the current post_material instance
#show a label with object.asset_file_name
else
#render materials_form.file_field :asset
end