I am pretty new to Ruby on rails. I have one query
I have one view (say view1) in which I am showing a drop down. For that I have passed and array and populating the drop down using that array like dis
<td><=% select_tag, options_for_select(#businessApprovers)></td>
So when I submit the form it goes to an action which intrun renders another view which has 5 tabs in body and each tab has a partial view. one of them calls my previous view view1. Now when it calls the view1 it again shows the drop down. instead it should show only one value and that too non editable.
we are having some other drop down too but they have hard coded values. We are doing that like this:
<td><=% f.field :contries, :condition_select, [abc,pqr] ....
and above thing is working fine. For that it is not showing drop down.
So I wanted to know how to avoid that drop down. Also what is the use of "f.field" because I removed that and from then on it is causing this problem.
Firstly, field is for CSV, text_field is a thing. Is that what that should be? Also, I'm hoping that's not exact code.
Instead of:
<td><=% f...
It should be:
<td><%= f...
That aside, if you're simply looking to display a select field when no selection has yet been made and simply text when it DOES have a value, then it would be as simple as using a conditional:
<% if thing.something.empty? %>
<%= f.select ... %>
<% else %>
<%= thing.something %>
<% end %>
If my assumptions were incorrect, please reply and I'll revise.
Related
I am using wice_grid and trying to get filtering to work.
#[controller].rb
def queue
#grid = initialize_grid(Indication)
end
#view
<%= grid(#grid) do |g|
g.column name: "id", attribute: "id" do |t|
t.id
end
end %>
Together, these make the table I want (I stripped down my original table to these bare bones and I have the same issue).
I can enter a value into the sorting field and click on the Y-shaped filter icon. Filtering appears to work correctly. However, after this, I can no longer change my filter (I can change the value in the box, but clicking on the filter icon again appears to do nothing), nor can I restore the full table by clicking on the grid icon.
If I reload the page, the value in the filter field reverts to whatever value was inputted the first time (as expected). I can actually run another filter/restore table, but after this action is taken, the grid appears to be locked again.
Any ideas what to do? Could this be a Javascript issue?
I feel dumb. RTFM!!!!
Needed to include jquery-ui in my javascript file.
I have a directory filled with partials. I'm looking to list ONLY the first h1 tags in each partial. The methods to accomplish this task could probably be modified to grab other elements as well.
Right now I use ruby to open each file, print out the first few characters, close file, and repeat. My ruby file parsing skills are limiting me. Here's the code I have at the moment:
<% Dir["app/views/partials/show/*.html.erb"].each do |f1| %>
<% aFile = File.open(f1, "r") %>
<% if aFile %>
<% content = aFile.sysread(20) %>
<p><%= content %></p>
<% else %>
<%= "Unable to open file!" %>
<% end %>
<% end %>
I also think I'm opening the entire partial in memory? Wondering If I can just read up until I find my h1 tag then close file and move on? Again I'm only reading first 20 characters because I haven't yet grasped a way to search for the first h1 tag.
I'll make edits as I work through the open, parse, piece... I appreciate any guidance and direction you can offer. Thanks!
EDIT:
Based on comments below there may be a far better way to accomplish my task. So I'm providing some additional background to get direction on other solutions.
This is for a slide show based on partials in a directory. The slide show is controlled with a navigation element which I would like to populate by the h1 tags in the partials. I'm not going to manually enter these things every time a change is made! I want the end user to simply drag and drop partials into a directory (with a certain name convention and h1 tag description for navigation) and let the slide show do everything else.
I could impose a class on the h1 tag "forNavigation" and on the content "sliderContent" and then use jquery to create a post load <ul> but that doesn't seem right. Plus they'll all be part of the same rendered div.
I guess I'm not clear why reading the first 50 characters of a partial, copying whats in the h1 tags, and putting it in a isn't the most elegant solution?
Like I said, above does everything needed except copy and print whats between the first h1 tag... With an xml parser or some regexp it'll be done. I'm just no good with parsing files.
Please let me know other methods to approach this. Right now I still think it's best to parse the partial (with or without rendering) and put what I need where I want it as needed.
Partials are not meant to be "parsed", but to be rendered inside other partials and templates. If you need to grab a part of a partial, you should probably extrat that part as a further partial, and use that inner partial in both the "listed" partial and in the "aggregated" view.
I have a model but one of its property is not displaying its value.
<% #medical_history.neonatalcourse %>
I already check my sqllite file and the value is there. So I am sure that I am saving the field. The problem is it not displayed.
Thanks
you need to use an equal sign with your tag to tell it to print the output of the ruby statement into the view. The version without the "=" is for when you don't wish to have a statement print its value into the page.
<%= #medical_history.neonatalcourse %>
I'm building an editor that works with .CSV files. I have the application importing the file fine, but now I want the user to be able to select a few columns to work with.
I display the top 5 columns of the file in an HTML table, and in the table TH tag I'm creating some checkboxes at the top of the table like this:
It ends up looking like this:
All of this is wrapped up in a form and when it gets submitted the params contain the IDs of the checked checkboxes/columns.
"0"=>"0",
"3"=>"3"
I want to find out which columns have been selected, but to my mind, scraping through the params and trying to work out which columns is a tad messy.... is there a way to get the selected checkboxes back as an array so I can just iterate through them? The number of columns is variable.
Solved!
Changed the checkbox generation to this:
and all of the selected columns go into an array called selected_columns. Simple!
Changed the checkbox generation to this:
<% 0.upto(#column_index_max) do |column_index| %>
<%= check_box_tag "selected_columns[]" , column_index %>
<% end %>
and all of the selected columns go into an array called selected_columns. Simple!
Ok, I think this is probably an easy question but for the life of my I can't figure it out. I have created a table called ugtags and in that table I have two columns (beyond the basics), 'name' and 'link'.
I am trying to allow a user to add a link to a page. Ideally they would enter the link title (name) and the url (link) and in the view it would display the title as a link to the url that was entered in the link column.
I there a way to do it by simply affecting the <%= link_to h(ugtag.name) %> code?
You should just be able to do:
<%= link_to h(ugtag.name), ugtag.link %>
See the documentation for all of the relevant options.