I am using jruby, i want use pagination for my rails app
i used will_paginate but i think jruby does not support's for will_paginate.
it gives error "undefined method `total_pages' "
in my units_controller.rb
#units = Unit.paginate(:page => params[:page], :order => 'created_at DESC')
and in views(index)
<%= will_paginate #units%>
is there some other pagination gem which support jruby, because i read in doc of will_paginate in that it state that will_paginate may support jruby not sure
plz help
You can try kaminari and look at this railscast for an introduction
Related
I'm fairly new to ruby and working on building a front-end styleguide that has html snippets I'd like to render as haml into a pre tag. I'm building a helper for middleman and have figured out how to read an HTML file and output its contents. Now I'd like to convert the html to haml and output that.
Looking around it seems like the html2haml gem is what I want to use, though the doc on that gem seems to only cover using it on the command line, whereas I'm trying to add this functionality to a helper.
Here is what I have so far for a helper
helpers do
def render_snippet(page)
p1 = ("<pre><code>").html_safe
p2 = File.read("source/"+"#{page}")
p3 = ("</code></pre>").html_safe
p0+p1+p2+p3
end
end
Here is how I'm using the helper
= render_snippet "partials/examples/typography/elements.html"
To answer your question, this is how you can make a helper to use html2haml gem outside the terminal shell commands
# some_view.html.erb
<%= render html_2_haml("home/my_partial.html") %>
# app/helpers/application_helper.rb
module ApplicationHelper
def html_2_haml(path)
file_name = path.split("/").last
path_with_underscore = path.gsub(file_name, "_#{file_name}")
system "html2haml app/views/#{path_with_underscore} app/views/#{path_with_underscore}.haml"
"#{path}.haml"
end
end
Now i'd like to say this definitely will not work in production (as it's dynamically creating a new file and hosting services like Heroku just won't allow that) but if your just making yourself a development helper for this-and-that then perhaps this could be helpful to you.
I ended up working on this some more and ended up with the following:
def render_html2haml(file)
templateSource = preserve(File.read("source/"+"#{file}"))
haml = Html2haml::HTML.new(templateSource, {:erb => nil})
content_tag(:pre, content_tag(:code, haml.render))
end
I was hoping to use Codeception to handle a subdomain declared in Laravel 5
$router->group(array('domain' => 'admin.' . Config::get('app.host')), function()
{
Codeception appears to have an amOnSubdomain method for webdriver, but not for the Laravel 4 module.
http://codeception.com/docs/modules/WebDriver#amOnSubdomain
Is there a way to integrate this functionality with Codeception on Laravel?
I tried calling the action directly
$I->amOnAction('Auth\AuthController#showRegistrationForm');
But this throws an error
Can't be on action "Auth\AuthController#showRegistrationForm":
Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
A bit confused on how to proceed.
I set an alias with the as index and it worked for me:
Route::post('/login', ['as' => 'admin.login', 'uses' => 'AuthController#postLogin']);
$I->amOnRoute('admin.login');
I also submitted an issue to the codeception repo for this method to be added. I looked into moving the method over from another module that has it already but the laravel module does some different things with it's url and history, and don't have the time at the moment to look into it more. Hopefully that method will work for you.
https://github.com/Codeception/Codeception/issues/1505
I am trying to use jruby + page-object gem + Cucumber for a proof of concept. I used the following statement.
app_url = 'https:\\google.com'
page_url(app_url)
I get a
NoMethodError: undefined method `page_url' for #
However,
navigate_to(app_url)
works fine. page_url works fine in Ruby.
Is this the way this works in jRuby? Though navigate_to works, is this any different?
Thank you for your help!
page_url is a class method provided by including the PageObject module. It sets the url for the page so you can use the visit_page factory in your test:
object MyPage
include PageObject
page_url "http://example.com/"
end
In a test somewhere:
visit_page MyPage do |page|
page.some_object_element.do_something
end
navigate_to is browser functionality exposed directly in your test via some World magic.
Is there an equivalent of Common Lisp's *features* in Clojure, so you can detect the OS and other environment configuration? Or do I just go through the Java API for that?
Probably use the Java API. It's easy enough, no sense re-inventing the wheel.
user> (System/getProperty "os.name")
"Linux"
user> (System/getProperty "os.version")
"2.6.36-ARCH"
user> (System/getProperty "os.arch")
"amd64"
To add to Brian Carper's answer, you could easily create a map of system properties via the Java API and bind it to the symbol features:
(def *features* {
:name (System/getProperty "os.name"),
:version (System/getProperty "os.version"),
:arch (System/getProperty "os.arch")})
Which gives you this structure, for example:
{:name "Windows 7", :version "6.1", :arch "x86"}
Then access a property in any one of the following ways:
(:name *features*)
(*features* :name)
(get *features* :name)
Whichever floats your boat.
Other answers are handling how to get the system info from Java pretty well. If you want more help interpreting it, here are some examples of how Terracotta did that:
VendorVmSignature
VmVersion
Vm
I am a student that currently enrolled in a Information Technology program and have been given a project that requires my team and I to create a dynamic form builder using Rails 3 + Ruby 1.9.2. A key feature of this dynamic form builder will be for users to export the results of their form. I haven't had much success implementing the CSV feature using the CSV class defined in the Ruby 1.9+ API. I define an "export" function in the form_results controller and am currently just trying to write to a CSV file. My export function looks like this:
def export
CSV.open("/public/results/results.csv", "wb") do |csv|
csv << ["sample", "data"]
end
end
And in the view, I link to the function by using:
<%= link_to 'Download CSV', form_form_results_path(#form), :method => :export %>
I feel that if I can get the implementation of the CSV class working properly, I will be able to finish off the rest of logic without any serious issues. Any guidance, input or help will be greatly appreciated.
Thanks,
Maz M.
Your use of the :method param is incorrect. This should be used to specify http verbs. Documentation here:
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
I would suggest using the respond_to block in the action where they are viewing the dynamic form, and use format.csv. This allows you to use the same action, but render the results in a different format by merely calling the action URL with .csv appended to the URL
respond_to do |format|
format.html
format.csv { render :text => #dynamic_form.to_csv} #this will return txt in browser
#format.csv { render :csv => #dynamic_form.to_csv} #with mime type (should prompt browser download)
end
Then in your form model you can create a to_csv def which will render the csv and return it as a string. You really should not put any logic like this in your controller. Controllers are meant for creating instance variables (where creation logic should be done in models) and forwarding to the proper views. The model should contain the bulk of your logic. google "skinny controllers, fat models" for more info on that.
def to_csv
csv = some_logic_here_to_create_csv_string
csv
end
Your link_to call would probably look like this (just writing this off the top of my head.. I cant remember if this is the correct syntax):
<%= link_to 'Download CSV', form_form_results_path(#form, :format=>:csv) %>
You should refer this link. This Railscast episode explains to export data in either CSV format or XLS format. You can also refer this link.