I have this line in my helper method
links << {:link => link_to('Overview', overview_index_path, :class => "bold"),
:active => (params[:controller] == "Overview")}
I want to link to a font-awesone icon instead of the text "Overview"
<i class="icon-bar-chart"></i>
I know this is something easy, but i can't remember it right now. Any help is very much appreciated.
Try
links << {:link => link_to('<i class="icon-bar-chart"></i>'.html_safe, overview_index_path, :class => "bold"),
:active => (params[:controller] == "Overview")}
Related
I would like to change the title on spree admin pages, and i`m trying to do that on deface:
Deface::Override.new(:virtual_path => 'spree/admin/shared/_header.html.erb',
:name => 'override',
:replace => 'title') do
'<title>MyOnly Administrativo</title>'
end
This is not working at all....
A little bit of work later I figured out what works, that is:
Deface::Override.new(:virtual_path => 'spree/admin/shared/_head',
:name => 'override',
:replace_contents => 'title',
:text => 'MyOnly Administrativo')
I am working on Redmine 1.4.x. I have two roles: client and employee. To separate the roles I have added is_client boolean attribute to the database. Here is the use case:
if is_client?
puts "it is client"
else
puts "it is employee"
end
Now depending upon this role I have to display Portal tab in the top menu. To achieve this I tried the following:
Redmine::MenuManager.map :top_menu do |menu|
menu.push :portal, "#", :html => {:id => "emp_portal", :onclick => "OpenEmployeePortal()"} , :if => (Proc.new { User.current.is_client? } && Proc.new { User.current.logged? })
end
But I couldn't succeed. It is showing the portal tab for both roles.
So how can I achieve this?
Try this
Redmine::MenuManager.map :top_menu do |menu|
menu.push :portal, "#", :html => {:id => "emp_portal", :onclick => "OpenEmployeePortal()"} , :if => (Proc.new { User.current.is_client? && User.current.logged? })
end
I'm currently working on a tour interface that guides new users around my site. I have a Tour model that has many TourStops, each of which contains information about a section of the site.
Basically, I'd like to write a function for the Tour model that -- when passed the number of a TourStop -- generates the correct class and data attribute for the HTML element it's attatched to. For example, I'd like
<%= link_to image_tag("new_button.png", tour.stop_data(1), :title => 'Add new asset'), new_asset_path %>
to call a function and return something like
def stop_data(order)
" :class => '#{tour_stops.find_by_order(order).name}',
:data => '{:order => order}'"
end
creating a link_to tag like:
<%= link_to image_tag("new_button.png", :class => 'tour_stop_1',
:data => {:order => 1}, :title => 'Add new asset'), new_asset_path %>
The above code doesn't work. Is something like this even possible? If not, what's a better approach I might take?
The image_tag accepts two parameters. A source, and a options Hash.
What you are trying to do is squeezing your return value from stop_data into this options Hash.
In order to get this to work, you first, need to return a Hash from stop_data, and second, make sure you pass only two arguments to image_tag - the source, and the options.
First:
def stop_data(order)
{
:class => tour_stops.find_by_order(order).name,
:data => { :order => order } # you may need order.to_json
}
end
Second:
link_to image_tag("new_button.png", tour.stop_data(1), :title => "Add new asset"), new_asset_path
This looks like it will work, but it won't, since your'e passing three parameters to image_tag.
When you do the following:
image_tag("new_button.png", :class => "tour_stop_1", :data => { :order => 1 }, :title => "Add new asset")
It looks like you're passing even 4 parameters to image_tag, but in fact they are only two. In Ruby, when the last parameter of a method is a Hash, you don't need to wrap the Hash key/value pairs in curly braces ({}), so the example above is essentially the same as
image_tag("new_button.png", { :class => "tour_stop_1", :data => { :order => 1 }, :title => "Add new asset" })
Now, to get your helper to work with image_tag, you need to merge the options, so they become only one Hash.
link_to image_tag("new_button.png", tour.stop_data(1).merge(:title => "Add new asset")), new_asset_path
Again, we're omitting the curly braces when calling merge, because it's only (and therefore last) parameter is a Hash. The outcome is the same as:
tour.stop_data(1).merge({ :title => "Add new asset" })
I have this
<%= link_to_remote "Next",
{:url => { :controller=>:objects,
:action=>:filter_recent,
:page=>#objects.next_page},
:with => "Form.serialize('filter')" },
:after => "alert('hello')"%>
I've tried :before, :after, :loading, :complete... none of them appear to be working... I know the button works, cause the table advances to the next page.
It looks like your arguments are incorrectly split up by the hash you wrapped them in.
Your :after JS snippet/callback is being passed to the html_options argument hash, not the options hash (where it would be used).
Change to the following:
<%= link_to_remote "Next",
:url => {
:controller=>:objects,
:action=>:filter_recent,
:page=>#objects.next_page
},
:with => "Form.serialize('filter')",
:after => "alert('hello')"%>
i am trying to call a remote method to update page content via ajax/js.
either i am too tired already or haml is not parsing the following code correctly to send the value of the query field via prototype. any ideas?
- form_remote_tag(:url => {:controller => "search", :action => "line"},:with => "'query=' + $('query').value" ) do
%input{:type => 'text', :id => 'query'}
%input{:type => 'submit', :value => 'Search'}
thanks a lot!
t
Have you tried a
= form_remote_tag
instead of
- form_remote_tag
I'm new to HAML myself but I was under the impression that you'll need the form tag to be actually generated not just executed...
Try passing the :with as part of the options hash.
- form_remote_tag({ :url => {:controller => "search", :action => "line"}, :with => "'query=' + $('query').value" }) do
If that doesn't work, debug the problem: Look at the generated html. Is the text field with id query the only element in the page with that id? Is the js code correct? Use the Firebug console to ensure $('query').value returns whatever you've entered into the text field.
Still stuck? Add your generated html into your question so we can better help.
EDIT: Your query input tag does not have a name attribute. Without a name, the javascript helper code skips that field when serializing the form fields...also, you do not need the :with code.
%input{:type => 'text', :id => 'query', :name => 'query'}