Ruby on Rails, Paperclip: "identify" command working in cmd but not in app - ruby-on-rails-3

I've installed ImageMagick on my Windows 7 64bit and I have the Paperclip Gem. My User model looks like this:
class User < ActiveRecord::Base
# Paperclip
has_attached_file :photo,
:styles => {
:thumb=> "100x100#",
:small => "150x150>" }
end
In paperclip.rb and development.rb I have:
Paperclip.options[:command_path] = 'C:/Program Files/ImageMagick-6.6.7-Q16'
My _form looks like this:
<%= form_for(#user, :html => { :multipart => true } ) do |f| %>
<% if #user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% #user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :username %><br />
<%= f.text_field :username %>
</div>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :crypted_password %><br />
<%= f.text_field :crypted_password %>
</div>
<div class="field">
<%= f.label :password_salt %><br />
<%= f.text_field :password_salt %>
</div>
<%= f.file_field :photo%>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
enter code here
I'm getting the following error when uploading an image:
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: C:/Users/John/AppData/Local/Temp/stream20110212-6576-1us1cdl.png is not recognized by the 'identify' command.>
I'm able to use identify in my cmd on that image and it returns metadata about the image without problems.
Please help if you can. I've been stuck on this one issue for over a day now.

This is due to a bug in the Paperclip gem in lib/paperclip/command_line.rb file.
def full_path(binary)
[self.class.path, binary].compact.join("/")
end
The full_path function generates command file name with a backslash.
"C:\Program Files\ImageMagick-6.7.0-Q16"/identify
This command fails on Windows as the cmd shell throws an error when the command file is a long file name with a back slash.
There are two ways to fix the issue.
Use the short file name as the command path.
Paperclip.options[:command_path] = 'C:/PROGRA~1/IMAGEM~1.0-Q'
Note: You can get the short file name as follows:
dir /x "C:\Program Files*"
dir /x "C:\Program Files\ImageMagick-6.7.0-Q16*"
Monkey patch the Paperclip gem in config\initializers\paperclip.rb.
I tested this on 2.3.11.
class Paperclip::CommandLine
def full_path(binary)
[self.class.path, binary].compact.join(File::ALT_SEPARATOR||File::SEPARATOR)
end
end
Now, the identify command is generated with the correct path seperator.
"C:\Program Files\ImageMagick-6.7.0-Q16"\identify
I prefer the second approach as command_path is easier to configure.

Updated the following in development.rb and it started working
Paperclip.options[:command_path] = 'C:/Progra~1/ImageM~1.8-q'
This was on a Windows 2008 32 Bit Server

Open a command prompt and type echo %path% your imagemagick path should appear there.
Also try changing the :command_path to C:/Progra~1/ImageM~1

Related

Syntax Error in code for 'bootstrap Custom forms' in Ruby

<%= form_for :content, url: contents_path, method: :post do |f| %>
<%= f.label :inout %> <!-- 수입 지출 목록 -->
<%= f.text_field :inout %><br>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">Options</label>
</div>
<select class="custom-select" id="inputGroupSelect01">
<option selected>Choose...</option>
<option value="1">결혼식</option>
<option value="2">장례식</option>
<option value="3">돌잔치</option>
</select>
</div>
<% if option == 1? %>
<%= f.hidden_field :category, value=>"결혼식" %>
<% end %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :cost %>
<%= f.text_field :cost %>
<%= f.label :memo %>
<%= f.text_area :memo %>
<%= f.submit %>
<% end %>
I'm getting the following syntax error in my code :
Unexpected ";", expected ";" .... syntax error, unexpected keyword_ensure, expecting_end_of_input
enter image description here
If I select option value one, I store "결혼식" in category
and I want to see "결혼식" in the show view
Can you identify what is causing the error?
Did you copy and paste the code from somewhere else? It's quite possible there might be some zero-width space or other hidden characters in your code that the ruby compiler is not liking.
You can use sublime text on OS/X or Notepad++ to try and see if there are hidden characters in your code.
If you're on OS/X or Linux, you can use Sublime Text and this plug-in to identify those characters
https://pastebin.com/ehWxNfMe
# http://sublimetext.userecho.com/topic/104394-is-it-possible-to-show-all-characters-spaces-tabs-cr-lf-etc/#comment_180170
import sublime_plugin
class ShowZeroWidthSpace(sublime_plugin.EventListener):
def on_modified(self, view):
spaces = []
p = 0
while 1:
s = view.find(u'\u200b', p + 1)
if not s:
break
spaces.append(s)
p = s.a
if spaces:
view.add_regions("zero-width", spaces, "string")
else:
view.erase_regions("zero-width")
If you're on Windows, you can try using Notepad++ and changing the encoding to Encode in utf-8 BOM
If allo , you can also create a new ruby file and type in the code manually to ensure there's no zero-width or invisble characters that ruby doesn't like.
Rails 4 - syntax error, unexpected tIDENTIFIER, expecting end-of-input
How to remove non-printable/invisible characters in ruby?

Rails bootstrap-datepicker-rails not working

I have a Rails 3.2.19 app using twitter-bootstrap-rails 2.2.6 and bootstrap-datepicker-rails 1.3.0.2.
I am trying to get a text_field in a form to display the datepicker but nothing happens when I click or focus on the field.
When I inspect the element I see the following:
<input data-behaviour="datepicker" id="project_due_date" name="project[due_date]" size="30" type="text">
When checking the console I do not receive any JS/Coffee errors.
Here is my code:
projects.js.coffee
$(document).on "focus", "[data-behaviour~='datepicker']", (e) ->
- $(this).datepicker
- format: "yyyy-mm-dd"
- weekStart: 1
- autoclose: true
projects/_form.html.erb
<%= form_for(#project, :html => { :class => "well"}) do |f| %>
<% if #project.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#project.errors.count, "error") %> prohibited this contact from being created:</h2>
<ul>
<% #project.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.label :project_name %>
<%= f.text_field :project_name, placeholder: "Build Spreadsheet", required: true %>
<%= f.label :project_manager %>
<%= f.collection_select(:user_id, User.all, :id, :full_name)%>
<%= f.label :due_date %>
<%= f.text_field :due_date, 'data-behaviour' => 'datepicker' %>
</br>
<%= f.button :submit, :class => 'btn btn-info' %>
<% end %>
I've tried also calling it based on id and have had no luck. I see the same behavior in Chrome, Firefox, or Safari.
Any help is greatly appreciated.
It looks like my CoffeeScript was wrong. I changed it to the following:
$ ->
$('[data-behaviour~=datepicker]').datepicker(format: "yyyy-mm-dd", autoclose: true)
Now I'm able to select the field and the datepicker comes up.

Pass values of a submitted form to another controller in rails3

I have a simple form as follows
<% provide(:title, 'View Mail') %>
<h1>View Mail</h1>
<div class="row">
<%= form_tag('/mails/new') %>
<%= label_tag "Email Address" %><%= email_field_tag(:email) %><br>
<%= label_tag "Password" %><%= password_field_tag(:password) %><br>
<%= submit_tag "View my Mails" %>
</div>
<% end %>
What I actually want to do is capture the email and password field and forward them to another controller 'mails' so that I can use the value of email and password in that controller and then show the appropriate details.This is just a sample app for me to check something as I am new to rails.
What exactly should be in place of
<%= form_tag('/mails/new') %>
<% provide(:title, 'View Mail') %>
<h1>View Mail</h1>
<div class="row">
<%= form_tag('/mails/new') do %>
<%= label :email %>
<%= text_field :email) %><br>
<%= label :password %>
<%= password_field :password %><br>
<%= submit_tag "View my Mails" %>
<% end %>
</div>
<% end %>
You need to define 'mails/new' path, in config/routes.db to be able to access that path.
Hopefully it answers your problem.

how to give Row and Column size in following erb code

How do I pass rows and columns size parameters in following code
<div class="field">
<%= f.label :Personal %><br />
<%= f.text_area :Personal %>
</div>"
For the f.text_area you can re-size it by doing something like:
<%= f.text_area :personal, :id => "message", :cols => 10, :rows => 10 %>
Seen here text_area
See the following links that will be useful in the future:
Ruby on Rails
RDOC_Main

Custom model not working in rails 3.2.2

I am a newbie in ROR, so please help me with this.
I created a model named 'Customer' from rails console, in the database there is a table named 'Customers' and it has columns: id, name, address, gender, dob, credit_card, created_at and updated_at. So, to save these information I created a view such as:
<%= form_for(#customer) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :dob %><br />
<%= f.date_select :dob %>
</div>
<div class="field">
<%= f.label :gender %><br />
<%= f.text_field :gender %>
</div>
<div class="field">
<%= f.label :address %><br />
<%= f.text_field :address %>
</div>
<div class="field">
<%= f.label :phone_number %><br />
<%= f.text_field :phone_number %>
</div>
<div class="field">
<%= f.label :credit_card %><br />
<%= f.text_field :credit_card %>
</div>
<div class="actions">
<%= f.submit 'Order', :action => :save_order %>
</div>
this view would be called by 'public' controller, from action 'check_out'
the code for action check_out is as:
def check_out
#customer = Customer.new
end
and code for action 'save_order' would be:
def save_order
#customer = Customer.new(params[:customer])
if #customer.save
#somcode
end
end
but i am getting a problem in the view part, "undefined method `customers_path' for #<#:0x9f49814>" in the line which contains "form_for(#customer)"
what i am doing wrong ? I am using rails 3.2.2
Thanks in advance :)
You don't have route for customer controller actions. Just add this line to routes.rb file
resources :customers
This one will generate several helpers, one of them will be customers_path. You can list all path helpers by command
rake routes