hi I am taking date input in mm-yyyy format I want to print date in format of month_name-yyyy format. i have used strftime but i am not to able print the date as my required format.
index.html.erb code
<td><%= project_site.name.titleize %></td>
<td><%= project_site.created_at.strftime('%b-%Y') %></td>
<td><%= link_to ' View attendance', project_site.file, :class => "fi-page-export-csv" %></td>
<% project_site.manager_remarks.each do |manager_remark| %>
<% if manager_remark.decision == false %>
<td><%= 'Rejected' %></td>
<% elsif manager_remark.decision == true %>
<td><%= "Approved" %></td>
<% else %>
<td><%= "Pending" %>
<% end %>
<% end %>
<td><%= project_site.attendance_month.strftime('%b %Y') %></td>
<td><%= link_to 'Remark ', project_site %><span>(<%= project_site.manager_remarks.size %>)</span></td>
<td><%= link_to 'Edit', edit_project_site_path(project_site) %></td>
<td><%= link_to 'Delete', project_site, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
form.html.erb code
<%= form.label :name %>
<%= form.text_field :name %>
</div>
<!--
<div class="field medium-3 columns">
<%= form.label :date %>
<%= form.text_field :date, class: 'datepicker' %>
</div>
-->
<div class="field medium-3 columns">
<%= form.label :upload_attendance %>
<%= form.file_field :file, :class=> 'attendance-file' %>
</div>
<div class="field medium-6 columns">
<%= form.label :attendance_month %>
<%= form.date_select :attendance_month, { :discard_day => true, :discard_month => false, :discard_year => false },:class => 'datetime' %>
</div>
https://www.foragoodstrftime.com/ should help you out
Try:
<td><%= project_site.attendance_month.strftime('%B %Y') %></td>
%B denotes to full name of month in strftime.
Try this code snippet.
<td><%= project_site.created_at.strftime('%B-%Y') %></td>
I'm new at programming and I have a question related to making a form in Ruby on Rails. I'm making a database for storing products' units. These units are, upon creation, initially located at the storage. This location is stored in a column Unit model. Then I have a model Store and a model Remission.
class Unit < ActiveRecord::Base
belongs_to :store
belongs_to :remission
attr_accessor :into_remission
end
class Remission < ActiveRecord::Base
belongs_to :store
has_many :units
accepts_nested_attributes_for :units
end
class Store < ActiveRecord::Base
has_many :units
has_many :remissions
end
Store has_many :remissions and Remission has_many :units. The idea is that when I put some units for selling in a store I have to create a remission. This remission is the list of products that I gave the store so we both can have a reference of which products are at the store. So I have a form to create a remission in which you can select the store that would change the store_id(reference) of the Remission. I also want to select from this same form the units that would take part in this new remission changing the remission_id(reference) from each unit. For that I made a attar_accessor :into_remissions in the Unit model so I could change that to true in each unit that would end up in the remission with a checkbox. I having a lot of problems making this work, here is the code of my form:
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(#remission) do |f| %>
<%= render 'shared/error_messages_remissions' %>
#Here you select the store that would own the remission and the products
<div class="field">
<%= f.label :store_id, "Producto" %> <br/>
<%= f.collection_select :store_id, #stores.order(:name), :id, :name, prompt: "Select Store" %>
</div>
#Here its a dynamic table that display all the products in storage
<table id="products" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Product Name</th>
<th>Remission</th>
</tr>
</thead>
<tbody>
#HERE I WANT TO MAKE A CHECK_BOX THAT CHANGES THE INTO_REMISSION VALUE FROM EACH UNIT. SO IT MARKS THE UNITS THAT WOULD TAKE PART IN THE REMISSION
<%= f.fields_for :units do |ff| %>
<% #units.each do |unit| %>
<% unless unit.sold %>
<tr>
<td><%= unit.product.name %></td>
<td>
<%= ff.label :into_remission, "Nombre de tu Marca:" %>
<%= ff.check_box :into_remission%>
</td>
</tr>
<% end %>
<% end %>
<% end %>
</tbody>
</table>
<%= f.submit "Submit", class: "btn btn-primary" %>
<% end %>
</div>
</div>
Needless to say he check_box its now showing nor working.
I not sure how to make this work and any advices would be welcome as I'm new with rails and programming. Thanks
Try changing this:
<%= f.fields_for :units do |ff| %>
<% #units.each do |unit| %>
<% unless unit.sold %>
<tr>
<td><%= unit.product.name %></td>
<td>
<%= ff.label :into_remission, "Nombre de tu Marca:" %>
<%= ff.check_box :into_remission%>
</td>
</tr>
<% end %>
<% end %>
<% end %>
into this:
<% #units.each do |unit| %>
<%= f.fields_for :units, unit do |ff| %>
<% unless unit.sold %>
<tr>
<td><%= unit.product.name %></td>
<td>
<%= ff.label :into_remission, "Nombre de tu Marca:" %>
<%= ff.check_box :into_remission%>
</td>
</tr>
<% end %>
<% end %>
<% end %>
I think you should first iterate over the units and pass each unit separately into the fields for. That should solve the showing issue.
I know there are alot of questions on this, but after looking at about a dozen or so none of them appear to be the same problem. I have an "Action" model that I am just simply trying to edit and update. (fyi, this isn't a nested form, I'm not using devise, and this isn't an activeadmin problem...like virtually all other questions about this topic are). I'm getting
error:
unpermitted parameters: utf8, _method, authenticity_token when I do this.
Action params in Actions_controller:
def action_params
params.permit(:id, :call_answered, :is_customer, :category_id, :actiontype_id, :why, :reviewer_id, :reviewed, :spam, :lead)
end
IF I change it to:
params.require(:action).permit(:id, :call_answered, :is_customer, :category_id, :actiontype_id, :why, :reviewer_id, :reviewed, :spam, :lead)
end
than I get the below error (and I can't find any solution for this):
undefined method `permit' for "update":String
Actions Controller:
def edit
#action = Action.find(params[:id])
#actiontypes = Actiontype.all
#categories = Category.all
#lead_categories = #categories.where(lead: true)
#user = current_user
#reviewer = User.find(#action.reviewer_id) if #action.reviewed?
end
def update
#action = Action.find(params[:id])
if #action.update!(action_params)
binding.pry
flash[:success] = "Loop closed!"
redirect_to '/closingloop/actions?reviewed=false'
else
flash[:danger] = "Something Went Wrong! The loop was not closed!"
render :edit
end
end
def action_params
params.permit(:id, :call_answered, :is_customer, :category_id, :actiontype_id, :why, :reviewer_id, :reviewed, :spam, :lead)
end
View:
<%= form_for [:closingloop, #action] do |f| %>
<%= f.hidden_field :reviewer_id, :value => #user.id %>
<%= f.hidden_field :reviewed, :value => true %>
<table width="70%" align="center" class="table table-responsive">
<tr>
<th>Tracking Number</th>
<td><%= #action.company.tracking_phone_number %></td>
</tr>
<tr>
<th>Target Number</th>
<td><%= #action.company.phonenumber %></td>
</tr>
<tr>
<th>Opportunity Name</th>
<td><%= #action.opportunity_name %></td>
</tr>
<tr>
<th>Opportunity Address</th>
<td><%= #action.customer_address %></td>
</tr>
<tr>
<th>Opportunity Phone</th>
<td><%= #action.caller_phone_number %></td>
</tr>
<tr>
<th>Call Recording</th>
<td><%= audio_tag(#action.call_recording_link, controls: true) %></td>
</tr>
<tr>
<th>Duration</th>
<td><%= #action.duration %></td>
</tr>
<tr>
<th>Call Status</th>
<td><%= #action.call_status %></td>
</tr>
<tr>
<th>Date & Time</th>
<td><%= #action.created_at.to_formatted_s(:long) %></td>
</tr>
<% if #action.reviewed? %>
<tr id="row_reviewed_by">
<th>Reviewed By</th>
<td><%= #reviewer.first_name %> <%= #reviewer.last_name %></td>
</tr>
<% end %>
<tr><td colspan="2"> </td></tr>
<tr id="q_call_answered">
<th>Call Answered?</th>
<td>
<div class="radio-toolbar">
<%= f.radio_button :call_answered, true, class: 'call_answered_true' %>
<%= f.label :call_answered, "Yes" %>
<%= f.radio_button :call_answered, false, class: 'call_answered_false' %>
<%= f.label :call_answered, "No" %>
</div>
</td>
</tr>
<tr id="why_not_answered" style="display:none;">
<th>Why wasn't it answered?</th>
<td>
<%= f.select :why, options_for_select([["No Answer", "N"], ["Abandoned", "A"], ["After Business Hours", "H"]], #action.why), { include_blank: true } %>
</td>
</tr>
<tr id="q_opportunity" style="display:none;">
<th>Was it a opportunity?</th>
<td>
<div class="radio-toolbar">
<%= f.radio_button :is_customer, true, class: 'opportunity_true' %>
<%= f.label :is_customer, "Yes" %>
<%= f.radio_button :is_customer, false, class: 'opportunity_false' %>
<%= f.label :is_customer, "No" %>
</div>
</td>
</tr>
<tr id="opportunity_type" style="display:none;">
<th>Opportunity Type</th>
<td>
<%= f.select :actiontype_id, options_from_collection_for_select(#actiontypes, 'id', 'action_type', #action.actiontype_id), { include_blank: true } %>
</td>
</tr>
<tr id="reason_for_call" style="display:none;">
<th>Reason for Call</th>
<td><%= f.select :category_id, options_from_collection_for_select(#categories, 'id', 'reason', #action.category_id), { include_blank: true } %></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Save" id="save" class="btn btn-success" /></td>
</tr>
</table>
<% end %>
The main problem here is that if you have model named 'action', your params by default will be named in the same way, which collides with ActionController default params. The simplest solution is, I guess, renaming your model.
In my view I have the following:
<div class="subject edit">
<%= form_for(:subject, :url => {:action => 'update', :id => #subject.id}) do |f| %>
<%= render(:partial => "form", :locals => {:f => f}) %>
<div class="form-buttons">
<%= submit_tag("Update Subject") %>
</div>
<% end %>
In the same folder I have created a partial (_form.html.erb). But for some reason it is not rendered.
_form.html.erb:
<table summary="Subject form fields">
<tr>
<th>Name</th>
<td><%= f.text_field(:name) %></td>
</tr>
<tr>
<th>Position</th>
<td><%= f.text_field(:position) %></td>
</tr>
<tr>
<th>Visible?</th>
<td><%= f.text_field(:visible) %></td>
</tr>
I'm running rails 3.2.7. Can some see what I'm doing wrong?
Thanks!
A server reset fixed the issue. Doh!
I have this index.html.erb file:
<h3>Pažymiai</h3><br />
Nuo: <%= #begining_of_week = Date.commercial(2011, 48, 1) %>
iki: <%= #end_of_week = Date.commercial(2011, 48, -1) %>
<table class="macs">
<tr>
<th>Vardas, pavardė</th>
<th>Dalykas</th>
<% (#begining_of_week..#end_of_week).each do |d| %>
<th class="calendar"><%= d.day %></th>
<% end %>
</tr>
<% #students.each do |student| %>
<tr>
<td class="name" rowspan="<%= #subjects.count %>"><%=link_to(admin_student_path(student)) do %><%= student.name%><br /> <%= student.surname %><% end %></td>
<% #subjects.each do |subject| %>
<td class="subject"><%=subject.name%></td>
<% (#begining_of_week..#end_of_week).each do |d| %>
<% #mac = Mac.where(:student_id => student.id, :subject_id => subject.id, :date => d) %>
<% if #mac.blank? %>
<td class="calendar_mac" onclick="location.href='<%= new_admin_mac_path %>'"><center>
</center>
<%= link_to 'new_mac', new_admin_mac_path, :remote => true %>
</td>
<% else %>
<% #mac.each do |mac| %>
<td class="calendar_mac" onclick="location.href='<%= edit_admin_mac_path(mac) %>'"><center>
<%= mac.mac%>
<% end %>
<% end %>
</center></td>
<% end %>
</tr>
<% end %>
<% end %>
</table>
How to make if cell is empty to write new value, if cell has value make it editable, when click cell i want a popup window where you could edit or add new element to database. My table looks:
You can try the best in place gem and follow a sample screen cast by ryanb this might help you out