%p{style: "float: right;"}
= link_to "Report", blog_post, method: :Report, confirm: 'Why do you want to report?'
How to use a drop down menu if I want to have a pop up containing "Why do you want to report?" and a drop down menu containing the reasons under the question?
You should add jquery-rails: https://github.com/indirect/jquery-rails
Also you can follow this tutorial: http://joshhuckabee.com/jquery-rails-3
You may use twitter bootstrap drop down menus.
http://twitter.github.com/bootstrap/javascript.html
Download the bootstrap-dropdown.js file and put it your assets file.
Call dropdown by
$('.dropdown-toggle').dropdown()
There is also a demo about how to use that.
In Rails view template, you need simply write iteration over menu-elements:
<ul class="dropdown-menu">
<% #menu_items.each do |item| %>
<li><%= item.title %></li>
<% end %>
</ul>
then you need to add a little css/javascript magic to make this list looks like drop-down menu.
There's a plenty of tutorials about that topic, but much easier way, as was noted above, is simply to use twitter-bootstrap. http://twitter.github.com/bootstrap/javascript.html#dropdowns. (you may check this gem to include twitter-bootstrap into your rails app)
Related
I am using Refinery CMS version 2. I want to display the data through an Api call from another project. I want to know how much refinery support this and how. Also i want to use different menu for different pages then how should i do that? I ve used the refinerycms-menu gem but those menus are displayed in all the pages. How to restrict particular menu for particular page?
For display another menu in some other i just did this in my `layout/application.html.erb
<% if request.fullpath == "/PATH" -%>
<%= render "/refinery/NAME_OF_ANOTHER_MENU" -%>
<% else %>
<%= render "/refinery/header" -%>
<% end %>
I created another menu by using `gem refinerycms-menus'.
For api call i am still searching.
Thanks :-)
I need in Ruby on Rails a menubar with drop down facilities.
Almost everything is static except one.
There I need to display all categorys which the user has entered.
Do I need to use a Gem or Twitter Bootstrap for this or can this be done with a form helper ?
Roelof
You mean something like this?
Assuming user.categories exists, and the category model have a description attribute.
<ul>
<% user.categories.each do |cat| %>
<li><%= cat.description %></li>
<% end %>
</ul>
This would create list items based on every category of the user.
I am using Rails 3. Consider the following code listed at bottom.
1) Should links to other actions be done via href (href="/foo/bar") or via #id (id="#foobar_div")? In some document I read online. Providing an actual link to the href attribute tells the iPhone to execute an AJAX call.
If I provide an div#id instead, then it loads the page without ajax (the same way browsers do this). However, providing div#id's means that all content has to be declared a single page.
Whats the right way for calling other pages on the server?
2) Is there anything wrong with the code structure below? i.e. can I style my own span elements like this?
3) The demo pages indicate that all content should be in one page. However, Ryan Bates from railscast.com has an episode about jqtouch and his pages are separate. which is the proper way?
<ul>
<% #songs.each do |song| %>
<li class="arrow">
<%= link_to(song_path(song)) do %>
<%= image_tag(song.user.profile_image, :alt => 'profile image', :style => 'float:left;') %>
<span class="title"><%= song.title %></span>
<span class="artist">by <%= song.user.first_name %></span>
<span class="likes"><%= song.likes.count %> loves</span>
<% end %>
</li>
<% end %>
</ul>
For your first and third questions (which to me are the asking the same thing), it depends on the project you're working on.
If you're providing static contents, you can just load all the pages in one hit, hence using "id=#foobar_div", as long as there are not that many pages (as you don't want the users to hold the phone and look stupid in front of their friends waiting 30 minutes for your site to load).
If you're providing dynamic contents or there are too many pages for your site, you may want to use the AJAX approach, at least for some pages.
At the bottom line, you want to load as many static pages as possible while still keeping your site responsive.
For question 2, I'm not quite sure I got what you're asking. I can't see anything obviously wrong, but again, I'm not a rail programmer.
I am doing my first project using Ruby on Rails and need to display a set of radio buttons. It should behave exactly like a selection list. For usability reasons, I need it in a radio buttons format.
In my project, I use the collection select which also allows me to display on the edit page as follows:
select('project','project_type_id',#project_types.collect{|project_type|[project_type.name,project_type.id]}) <br>
I need something exactly like this, (especially the ability to display the selected value in the edit page) but using radio buttons.
I did a Google search and read the entire Rails guides on radio buttons but I can't find the answer.
How can I do this?
I suppose you can do it like this in your view
<% #project_types.each do |project_type| %>
<%= radio_button("project", "project_type", project_type.name) %> #assuming you have a name attribute on project_type
<% end %>
If you want a particular radio button to be checked then you can pass the checked option like so
<%= radio_button("project", "project_type", project_type.name, {:checked => true}) %>
This is probably easy but I'm a bit of a newbie on wrapping my head around these things sometimes.
Synopsis: I'm trying to make a checklist application that technicians go through and answer questions about what has been completed or done in the field. The technicians then submit this for review. The questions are created, managed, and updated by the managers.
UPDATE
I'm a designer, so I naturally magnetize to PS. Here's a photo of the concept: http://screensnapr.com/u/a9k1ps.png
checklist model contains: header, subheader, question, and answer.
Everything is a string, except the answer field, which is an integer for a check box.
I'm not quite sure which RESTful page to start with after that though. I need the header displayed like this (in view), but editable/submittable through the check box all on one page.
This view has to DISPLAY the checklist and EDIT the checklist at the same time. The manager needs to be able to add new headers, subheaders, and questions, which the technicians can then answer.
<% #checklists.each do |checklist| %>
<h1> <%=h checklist.header %> </h1>
<h3> <%=h checklist.subheader %> </h3>
<ul>
<li>
<%=h checklist.question %>
<% form_for #checklists do |f| %>
<%= f.check_box("checklist", "answer") %>
<% end %>
</li>
</ul>
<% end %>
Would this work and would it best to stick this in the index or edit action? Would I be better doing a partial of some sort? nested_attributes? I'm a bit lost at this point because I'm trying to manage two actions (index, edit) within one file.
If you want a manager to update/modify the checkboxes and the technicians to fill in the forms, you need a couple of extra tables. One containing the questions and one containing the values that are checked. Also, it seems better to split the controller into two, one for each user type:
For the manager part you can simply make a controller like any other controller: using the index action to show all questions and the edit/update/etc actions to modify them.
For the technician part you need to define a project table, containing some information about the project the technician is working on. And a checkboxes table containing the project_id and the checkbox_ids, in order to link the checkboxes to a certain project.
See A Guide to Active Record Associations for more information about creating associations between tables.
Without looking at this further, I'm willing to bet you want
form_for checklist.question and POST to questions_controller, which would use the #update action.