How is the easiest way to make a selectio field which will retrive other information? I have an Ajax script to make this, i think i can make it work. But srsly, i can't figure out how to make in the view or controller actions to let me select a data from the table and get other data related to it.
This is my code, this may help understand what i'm trying to say.
<%= form_for(#page) do |f| %>
<div id="jstree">
<ul>
<li> <%= f.collection_select :cliente_id, Cliente.order(:name), :id, :name, prompt: "Selecionar", :required => true %>
<ul>
<li id="child_node_1"><%= f.projeto.name %>
<ul>
<li id="child_node_2"><%= f.task.descr %></li></li></ul>
</ul>
</li>
</ul>
</div>
Related
I tried different ways to display a picture in my rails app,and when the user clicks on that he should be redirected to the URL i specify.
I tried this method,"rails method"
<li <%= link_to new_gig_path %><%= image_tag 'v.png' %></li>
and just the image was showing,but the image wasn't clickable.
than i tried this"HTML method" <img src="link to an image"/>
And it worked as i wanted,the image appeared,and when i clicked on it,it redirected where i wanted.The problem is that it is wrapped in <a></a> tags,but i need the code to be wrapped in <li></li> tags,
note:I also tried to wrap the <a></a> tags in <li></li> tags but it destroyed my design,i do need it to be just in <li> tags
looking into my navigation bar,you see that my nav-bar is structured in <li>tags
#instead of this comment I want to put the code,i am asking help with
<li><%= link_to '+Add Box', new_gig_path, id: "addgig" %></li>
<li><%= link_to 'Edit Profile',edit_user_registration_path, id: "menu-overwritten" %></li>
<li><%= link_to "Log out", destroy_user_session_path, :method => :delete, id: "menu-overwritten"%></li>
More info:
Also i tried this method
<li><img src="a link to an image" height="30" width="159" ></li>
This time it worked as well,but i don't think it is gonna be responsive if i leave this method.This is definitely not the rails way.
Thank you.
<li>
<%= link_to new_gig_path do %>
<%= image_tag 'v.png', class: 'your-class' %>
<% end %>
</li>
I would know if it is possible to do something like this with a Rails wice grid plugin:
<g.column do |model| %>
<ul class='list-inline'>
<li>
<%= link_to model_path( model ), :title => 'See' do %>
<i class="glyphicon glyphicon-eye-open"></i>
<% end %>
</li>
<!-- ... -->
</ul>
< end -%>
Is it possible for a wice grid column to contain an HTML <ul> tag?
I was searching for the same but finally figured it out. So adding this as an answer though its too late but might help someone else.
I think we can't use ERB in the grid column but we can use Ruby/Rails code in there.
I think we can use HTML like this but have to use html_safe option
"<ul class='list-inline'><li><a href='#'><i class='fa fa-eye'></i></a></li></ul>".html_safe
But i preferred this to generate the HTML.
g.column do |model|
content_tag(:ul, class: 'list-inline') do
concat(content_tag(:li, link_to('<i class="fa fa-eye"></i>'.html_safe, controller_path(model), title: 'See')))
concat(content_tag(:li, link_to('<i class="fa fa-wrench"></i>'.html_safe, edit_controller_path(model))))
end
end
I am trying to highlight curent link. I used this question for ideas here
I have simple menu, that is based on this structure:
<li>
<%= #waste_root.name %>
<ul>
<% #wast_child_ids.each do |it| %>
<li><%= link_to it.name, products_path(:category => it.name), class: "#{cp(products_path)} additional_class" %>
</li>
<%end%>
</ul>
</li>
In Aplication helper:
def cp(path)
"current" if current_page?(path)
end
In CSS file:
.current {
color:red;
}
What I get is all links are in red color. I don't get it. For others it worked just fine.
I think your path in view should look like this:
<li>
<%= #waste_root.name %>
<ul>
<% #wast_child_ids.each do |it| %>
<li><%= link_to it.name, products_path(:category => it.name), class: "#{cp(products_path(:category => it.name))} additional_class" %>
</li>
<%end%>
</ul>
</li>
Because, you're passing a param category in products_path and hence current_page? isn't able to judge the correct relative path. Also, it'd be better if you use the _url(complete path) instead of relative path. It'll be much clear to cross check and to understand as well.
You need to pass the category.
<%= link_to it.name, products_path(:category => it.name), class: "#{cp(products_path(:category => it.name))} additional_class" %>
They're all on the products path because you're just differentiating based on parameters. So just passing the products path they all return true, you need to differentiate based on the parameters by passing them too as you've done in your link
I have a sidebar that contains links to all of a users :shopping_lists. Upon clicking on one of those links, I'd like to render a page showing the :list_items in that particular list. Here's my sidebar partial:
<aside class="sidebar-nav-fixed">
<h1>My Lists</h1>
<% if user_signed_in? %>
<% current_user.shopping_lists.each do |l| %>
<ul>
<%= link_to "#{l.name}", '#' %>
</ul>
<% end %>
<% else %>
<h5><%= link_to "Sign in to manage lists.", new_user_session_path %></h5>
<% end %>
</aside>
My question is: what path would I be putting in place of my current stub link in order to route to the correct list? Thanks in advance!
That will depend on how your routes are setup. I would expect shopping lists to always be in the context of a user, so probably something like this:
<%= link_to l.name, user_shopping_list_path(current_user, l) %>
If shopping lists are a top level route, then probably something like this:
<%= link_to l.name, shopping_list_path(l) %>
There are couple of things you can do, granted your routes are setup correctly:
The easiest is:
link_to "#{l.name}", l
Rails should create a link something similar to http://host/shopping_lists/2
The above is a shorthand for
link_to "#{l.name}", shopping_list_path(l)
To see a list of available routes and methods you can run:
bundle exec rake routes
in the root of your rails app
I have a loop that creates a list of works from the modal work
//does work but want test to be <%= work. name %>
<ol class="meny-control mobile">
<% #works.each do |work| %>
<li class="" data-id="<%= work.id %>"><%= link_to 'test', work %></li>
<% end %>
</ol>
//doesnt work but want it to
<ol class="meny-control mobile">
<% #works.each do |work| %>
<li class="" data-id="<%= work.id %>"><%= link_to '<%= work.name %>', work %></li>
<% end %>
</ol>
As you would guess the <%= work.name %> throws a syntax error. How do I correctly format the link_to to display each work.name as the 'path' && the anchor's inner html as work.name.
Being new to rails, I'm still really iffy on understanding documentation properly. Could you please reference from link_to() (if even there) where this format is explained so I use this for future referencing & understanding --also how to properly edit the stack question title for future similar question.
The error is because of the nesting of <% tags and I suppose you already are aware of that. To solve your problem use the following:
<%= link_to "#{work.name}", work %>
The #{} is used to interpolate variables, i.e. replacing variables with their values within the string literals as in link_to "#{work.name}" above where work.name will be replaced by the value work.name holds.
you don't need "#{}".
you can write this:<%= link_to work.name, work %>