as i am a beginner to rails...
i have installed gem 'thinking-sphinx' (3.1.3, 2.0.10) in my file using rails4
and rvm 2.0.0
i wrote this action in my controller
and inside index page added form_tag
in the same file added this script
in search box its not showing searched results
but in terminal it is showing as
routes.rb
resources :patients do member do
put :update_status
end
collection do
get :search get :search_sphinx
end
Related
In a Rails 4 project I have been tasked with merging an “about” page to the end of PDF documents that have been uploaded via Paperclip.
The issue is that some of the uploaded pdfs contain optional content. I started out using combine_pdf but it does not support files with optional content as explained here. I have tried Prawn but it no longer support this functionality. I finally found the PDF Toolkit gem but the documentation does not say anything about optional content support. PDF Toolkit is a command line tool that has been wrapped in a Gem and therefore operates outside of the Rails application. I have tried using these command line examples in my CLI: pdftk file1.pdf file2.pdf cat output out_file.pdf but the terminal just hangs indefinitely.
The gem's documentation here is very unclear (to me) and may be the source of my issues.
My hope is to find advice on how to accomplish this using PDF Toolkit OR a better library for merging PDFs with optional content.
I have gotten this far by researching Stack Overflow questions like this and this
My OS is OSX 10.11.6
existing_pdf_path = #report.document.file.path
# Create a html template and convert it to pdf
about_company_html = render_to_string("_about_company.html.erb", layout: false)
about_company_pdf = WickedPdf.new.pdf_from_string(about_company_html, orientation: 'Landscape')
# Save about_company_pdf to file in tmp/pdf
about_company_pdf_path = Rails.root.join('tmp/pdf', 'about_company_partial.pdf').to_s
File.open(about_company_pdf_path, 'wb') { |file| file << about_company_pdf }
# Create and save a blank target file we will save everything to
combined_pdf_path = Rails.root.join('tmp/pdf', 'combined.pdf').to_s
FileUtils.touch(combined_pdf_path)
# This returns false OR just hangs depending on my exact syntax, no error or backtrace
result = PDF::Toolkit.pdftk( *%w(existing_pdf_path about_company_pdf_path cat output combined_pdf_path) )
I have tried as many variations of the above call to pdftk as I can find or think of. For example PDF::Toolkit.pdftk( existing_pdf_path, about_lux_pdf_path, 'cat', 'output', combined_pdf_path ) with no results.
I have a CoffeeScript file called subscribers.coffee.erb
$(document).ready ->
stripe = require('stripe')('<%= Rails.configuration.stripe[:publishable_key]%>')
$('.pricing-get-started').prop("disabled", true)
$('.verify-coupon').click ->
# use stripe api to verify that the coupon is valid
return
return
The second line does not seem to be working. I have even tried to copy and past my publishable key but that doesn't work either. I think the following problems are:
require('stripe') isn't found
Rails cannot locate the publishable key from the coffeescript file
Note:
I have a working key. I can sign up for subscriptions and everything from my subscribers/new.html.haml.
I am using gem 'stripe'
Any advice would be greatly appreciated!
You're calling stripe = require('stripe'), but require isn't defined by default in javascript. As long as you have stripe.js included in your application before this script is called the require('stripe') line should be unnecessary.
Once Stripe.js is loaded you can set your publishable key via Stripe.setPublishableKey('pk_test_key_here');. If you're using an environment variable, be sure that Rails.configuration.stripe[:publishable_key] is defined in your environment.
Finally, you should be aware that any embedded ruby in an asset file included in your asset manifest (application.js or application.css) will not be called on each request, but will only be called when you run rake assets:precompile. Thus Rails.configuration.stripe[:publishable_key] may not always evaluate to a value you expect.
I'm using rails 4.0 with ruby 2.0.
And i've 100's of js and css files. I dont want them to load on all pages.
So i removed require_tree in application.js and application.css
I include the required css and js using
<% javascript_include_tag "js_file" %>
<% stylesheet_include_tag "css_file" %>
My questions are
1. Do i need to precompile assets?
2. Will they be formed into a single file and sent on client side?
3. What is and how can turbo_link gem help me here?
4. Should i use controller based assets and use their appropriate cs and js file for inclusion?
1. Do I need to precompile assets?
No, but it entirely depends on your production environment. Services such as Heroku require precompiled assets
2. Will they be formed into a single file and sent on client side?
The assets which are required in the application.css will be merged into that file. However, if you have controller-specific css/js, and call them from your layout accordingly, they should be compiled into their respective files
3. What is and how can turbo_link gem help me here?
Turbolinks is a gem designed to help boost page load times, by cutting down the number of times the elements have to be loaded. Basically, if you're using the same controller, turbolinks will just replace the part of your page with an Ajax request
So nope, Turbolinks won't help you with compilation / organization of your assets :)
4. Should I use controller based assets and use their appropriate cs and js file for inclusion?
It depends on your application. The first question I would have is.... why do you have 100's of CSS & JS files? After you find the answer to this, you can then work on making the system work to the most efficient requirements
i'm wondering how to use mercury gem with rails4.
i tried to follow guide http://asciicasts.com/episodes/296-mercury-editor
if i load page within editor ( /editor/pages/1) i see error in javascript console:
Uncaught TypeError: Cannot read property 'konqueror' of undefined
and mercury-region isn't visible at page at all
Gemfile:
gem 'mercury-rails', github: 'jejacks0n/mercury'
app/views/pages/show.html.erb:
<div id="page_body" class="mercury-region" data-type="editable">
<%= raw(#page.body) %>
</div>
after some delay i get javascript alert with message:
Mercury.PageEditor failed to load: Region type is malformed, no data-type provided, or "Full" is unknown for the "page_body" region.
Please try refreshing.
mercury is utilising jquery.browser this method is deprecated in the most recent update.
If you include gem 'jquery-migrate-rails' in your gemfile that you should work favourably until mercury updates it's code to the latest jquery or at least 1.9
You'll need to add
//= require jquery-migrate-min
to your application.js after jquery is loaded.
I just had the same issue. I describe it better in my own question here, but basically the issue comes from a deprecated jquery method calling 'konqueror'. I don't think it had anything to do with your app being in rails 4 btw. I'm in gem 'rails', '3.2.13'
I'd up-vote the question but apparently I need more reputation. hint, hint :)
I had a similar issue with this because of turbolinks. I just disabled its JS in applications.js:
//= require turbolinks
~to:
// require turbolinks
-until I figure out how to get them to play nicely together. At least for the Mercury pages, have to poke them somehow.
I have some issues too, it does seem to be an issue with Turbolinks. I was able to get by it by removing the line:
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
from my application.html.erb file, not sure if this will cause issues down the road
Is there a relatively easy solution to Rails 3 auto escaping to not break view-oriented plugins? I'm using table_builder which has an api along the lines of:
<%= calendar_for(args) do |table| %>
...
<% end %>
Unfortunately, rails goes through and escapes all the html generated from that plugin. Is there an easy way to avoid this behavior that doesn't involve me hacking on the plugin itself? I can't really wrap it in a raw() from what I know because its an erb block.
take care which fork you put in your gemfile, this one works with rails3 as a gem like demonstrated in the railscast: http://railscasts.com/episodes/213-calendars
https://github.com/jchunky/table_builder
use this in your gemfile
gem 'table_builder', '0.0.3', :git => 'git://github.com/jchunky/table_builder.git'