In my application_helper.rb file I have a function like this:
def internal_request?
server_name = request.env['SERVER_NAME']
[plus more code...]
end
This function is needed in controllers, model, and views. So, I put this code in a utility function file in the lib/ directory. However, this did not work: I got complaints about requ...
So my question is how would you implement your handwritten Helpers based on the role of current user.
Would it be efficient to change the behaviour at request time? e.g. the Helper somehow figures out the role of user, and include the proper SubModule?
module ApplicationHelper
module LoggedInHelper
# Some functions
end
...
Is there a way that I can create a custom form helper so that instead of:
special_field_tag :object, :method
I can achieve something like:
form.special_field :method
...
I have a strange error that came about when I changed my app from mongrel to mod_rails.
My app changes from a two column layout to a three column layout depending on where the user is in the app. My application layout relies on several helpers to put the divs in the right place.
In application_helper.rb:
def left_column_layouts
i...
I'm trying to create a slug helper in Sinatra. Here's the code (as seen here):
helpers do
def sluggify(title)
accents = {
['á','à','â','ä','ã'] => 'a',
['Ã','Ä','Â','À'] => 'A',
['é','è','ê','ë'] => 'e',
['Ë','É','È','Ê'] => 'E',
['í','ì','î','ï'] => 'i',
['Î','Ì'] => 'I',
['ó','ò','ô','ö','õ'] => 'o',
...
I have a time_select in which I am trying to set a time value as follows;
<%= f.time_select :start_time, :value => (@invoice.start_time ? @invoice.start_time : Time.now) %>
This always produces a time selector with the current time rather than the value for @invoice.start_time.
@invoice.start_time is in fact a datetime object but thi...
I'm making a tool for my university that allows students to create a list of classes by doing the following:
Searching by course title for their course via an autocomplete input field.
Adding that course to a separate form that upon being submitted creates a course list.
I am trying to link the autocomplete and the course list form w...
When I write
module ApplicationHelper
def flash_helper
flash.each do |key, msg|
content_tag :div, msg, :class => key
## "<div class=\"key\">" + msg + "</div>"
end
end
end
I do not get anything unless I return the statement. The HTML is escaped in my view when I call <%= flash_helper %>. What gives? How can ...
All frameworks aside, what are some of the common helper functions/prototype methods you use on a daily basis?
Please note I am not arguing against frameworks. I've simply found that the majority of what I do on a daily basis can, most often, be done with a few dozen Array, String and Element.prototype methods. With the addition of a fe...
Im trying to get an 'add to cart' button to work. When I use <%= button_to "Add to Cart", :acton => "add_to_cart", :id => @product %> and then click the button, I get a URL that puts the action after the ID, like this: http://localhost:3000/store/show/1?acton=add_to_cart The cart page does not load.
What I need is a URL that looks li...
I am probably going to need to refactor in two steps since I'm still developing the project and learning the use-cases as I go along since it is to scratch my own itch. I have three models: Letters, Calls, Emails. They have some similarilty, but I anticipate they also will have some different attributes as you can tell from their desc...
I'm looking for an image url helper for sinatra that allows me to do something similar to staticmatic's, where I can shortcut to a relative path like so...
=img "me.jpg"
Can anybody point me in the direction to where this might be online, or where I could learn how to write one, or provide an example of one they have already written
...
I've got a CopiesHelper module with a method cc.
In my ApplicationController, I have
helper :all
helper_method :cc #just tried putting this in recently
If in another one of my Controllers, I try using the cc method, I get
undefined method 'cc' for #<OtherController:0xblublublublub>
Am I missing a step here?
...
I see there is one for staticmatic,
and plenty in the Ruby toolbox for rails menu builders,
but I can't seem to track one down specifically for Sinatra.
...
I have some page helpers in application, something such as:
# ajax_helper.rb
module AjaxHelper
def update_counter(new_value)
page.replace_html :counter, :partial => 'counter', :locals => { :value => new_value}
end
end
# update.fbjs.rjs
....
page.update_counter(new_value)
.....
What is the best way to test this helper method?
...
I want use on my rails helper a script as follow:
select_tag(:article_id, option_groups_from_collection_for_select( @article, :categories, :name, :id, :name, :include_blank => "Select one category"))
but in my script, nothing happens. How can I use option_groups_from_colletion_for_select with include_blank method?
...
We are currently in the process of upgrading our rails version and I have come across some weird error in one of my date_select tags.
Here is the culprit:
<%= date_select :consultant_assignment, :start_date, :order => [:day, :month, :year],
:start_year => 5.years.ago.year, :end_year => 5.years.from_now.year, :use_short_month => t...
I am using the Rails helper datetime_select in one of my forms. I currently have a requirement to change the dropdowns for day, year, hour, and minute to be textboxes with validation. Is there a way I can specify that I want textboxes for these fields? Or possibly a different helper that will do what I need?
here is my usage:
datet...
Does anyone know a better way of displaying the contents of an activerecord result set as a select box.
I would like todo this
@users = User.all
<%= f.select_box :users, options_for_select(@users) %>
But for now I need to parse all the users into a multidimensional array with a sub array [username,user_id]
Any ideas?
...
So this is a newbie rails design question. Lets say I want some of my common functionality to be sitting in a set of helper classes (either as class methods or instance methods).
And I want to use these helper objects inside controller (not view) or even may be a model. can I do that? how? Does it have to be a module or class or can be ...