How can I add my own name to an input, e.g. a textbox?
i.e. how can I customize the input name that is displayed beside an input?
Here is my code:
- title "Add a NEO"
= simple_form_for #neo do |f|
= f.input :name
br
- for obs in #observations do
= simple_form_for obs do |o|
table
tr
td = o.input :ra
td = o.input :dec
= f.button :wrapped, "Create NEO"
I would like to specify text for o.dec and o.ra. How can I do that?
- title "Add a NEO"
= simple_form_for #neo do |f|
= f.input :name
br
- for obs in #observations do
= simple_form_for obs do |o|
table
tr
td = o.input :ra, :label => "Right Ascension"
td = o.input :dec, :label => "Declination"
= f.button :wrapped, "Create NEO"
Related
I am trying to create an advanced search form for a rails blog
I'm trying to avoid using a gem
I have a table posts with a title, location_id and category_id, the last two are connected to two tables Location (:small, :greater) and Category (name), but I doubt that's important for this question
I have a search form which finds all posts where location_id and category_id is equal to the user set option
<%= form_for(#advanced_search) do |f| %>
<div class="field">
<%= f.label :category_search %><br>
<%= f.collection_select :category_search, Category.all, :id, :name, :
include_blank => "any category" %>
</div>
<div class="field">
<%= f.label :location_search %><br>
<%= f.collection_select :location_search, Location.all, :id, :locationsmallgreat
,:include_blank => "any city" %>
<%= f.submit %>
<% end %>
Once again i doubt that's important for the question which is probably simpler than I'm explaining it to be
Basically I have this so far
#posts = Post.all
#posts = #posts.where('category_id = ?', #advanced_search.category_search) if #advanced_search.category_search != "any category"
#posts = #posts.where('location_id = ?', #advanced_search.location_search) if #advanced_search.location_search != "any city"
But it doesn't seem to work
I need it to work as so, If the form has Category = Any category (:included_blank => "any category)
and Location = London
It would search for all Posts where location is == london, BUT it would remove the .where for the category, seeing that it is == any city and vice versa if a Category was selected and Location was left blank (:included_blank => "any city)
Thanks
if #advanced_search.category_search.present? && #advanced_search.location_search.present?
Post.
where('category_id = ?', #advanced_search.category_search).
where('location_id = ?', #advanced_search.location_search).
all
elsif #advanced_search.category_search.present?
Post.
where('category_id = ?', #advanced_search.category_search).
all
elsif #advanced_search.location_search.present?
Post.
where('location_id = ?', #advanced_search.location_search).
all
else
Post.all
end
I,m using bootstrap-datepicker-rails gem for date picker and want to shoe calender only on icon click(not on clicking text filed).
Write Now I'm using in my form:
= form_for (ServiceExp.new), :remote => true do |s|
%ul
%li
= s.label :position
= s.text_field :position
%li
= s.label :start_date
%p
From
%li
.input-append.date.datepicker
= s.text_field :start_date, :class =>"input-mini"
%span.add-on
.calander-icon
To
.input-append.date.datepicker
= s.text_field :end_date, :class => "input-mini"
%span.add-on
.calander-icon
%li
= s.label :description
= s.text_area :description
= s.submit 'Save',:class => "btn btn-primary"
And in javascript:
$('.datepicker').datepicker();
Here, Calendar shows on both text field and icon because class datepicker on top of both. If use this class only on icon than it show calender only on icon click but not adding value on text field. How can I achieve that one. please give any suggestion !!
Add :"data-date-format" => 'dd-mm-yyyy', :'data-date' => '12/2/2013' # default date
To div container containing input box and span.
Like
%li
.input-append.date.datepicker{:"data-date-format" => 'dd-mm-yyyy', :'data-date' => '12/2/2013'} # default date
= s.text_field :start_date, :class =>"input-mini"
%span.add-on
.calander-icon
I am using Meta-search Gem to search from table by below controller action. I am Using The Rails version 3.2.9.
class FeedEntriesController < ApplicationController
def index
#search = FeedEntry.search(params[:is_star])
#feed_entries = #search.page(params[:page])
#app_keys = AppKey.all
end
end
feed_entries table contain is_star:boolean attribute. So, I just want to pass the hash parameter is_star == true into the params[:is_star] from view using form_for or link_to . I tried using the below way.
In Views/feed_entries/index.html.erb
<%= link_to "Stared", {:controller => "feed_entries", :action => "index", :is_star => true }%>
but the above way is now worked, So I decided to make use of form_for in the below way,
<%= form_for(#is_star) do |f|%>
<%= f.hidden_field :is_star_is_true %>
<%= f.submit "Search" %>
<% end %>
But, nothing is worked, please someone help me resolve this problem.
true and false when passed as a string is parsed as their truthy value when used in a boolean column. This is also true for 0, 1, '0' and '1'
>> m = Model.new
>> m.active = 'false'
>> m.active? # false
>> m.active = 'true'
>> m.active? # true
Knowing this, you can pass 'true' as the value of the hidden_field
<%= f.hidden_field :is_start, value: 'true' %>
You can pass in the value of the parent in the view where the form is being rendere ultimately with something like <%=params[:is_start] = 1 %> . I am not sure how the layout of the app is setup. Also make sure to attr_accessible :is_start
Update: I may have understood your problem wrong. So try this as well
<%= f.hidden_field :is_star, value: 'true' %>
Or you could have a radio button ?
<%= f.radio_button :is_star, value: 'true' %>
I want to see my room_requests which have duration included in my date range from form. Here's what I've done:
controller for this view:
def not_confirmed_slots
if params[:search]
#slots = RoomRequest.find(:all, :conditions => ['date >= ? and date =< ?', params[:start_date].strftime("%Y-%m-%d"), params[:end_date].strftime("%Y-%m-%d")])
if #projects.size.zero?
flash[:notice] = "No result found"
#slots = RoomRequest.find(:all)
end
else
#slots = RoomRequest.all
end
end
and my form from view:
%h1= t('headers.reports.notConfirmedSlots')
= form_tag not_confirmed_slots_reports_path, method: 'get' do
%p
= text_field_tag :start_date, nil, :class => "datepicker", :placeholder => t('placeholders.reports.startDate')
%p
= text_field_tag :end_date, nil, :class=>"datepicker", :placeholder => t('placeholders.reports.endDate')
.clear
.action_bar
= submit_tag t('buttons.reports.generate'), {class: "button blue"}
But every time I submit form with dates it lists me all room_requests from db - any tips?
Oh, and here is the partial (it's on the same view where is search form):
%table
- #slots.each do |s|
%tr
%td
= s.bookers_name
%td
= s.request_type
I'm using Rails 3.0.7 with awesome_nested_set and I'm trying to create a nested form which will allow me to enter a category and sub categories all in one create form.
Here is my category model, controller & form
category.rb
class Category < ActiveRecord::Base
acts_as_nested_set
end
categories_controller.rb
class CategoriesController < InheritedResources::Base
def new
#category = Category.new
3.times { #category.children.build(:name => "test") }
end
end
form
= form_for #category do |f|
-if #category.errors.any?
#error_explanation
%h2= "#{pluralize(#category.errors.count, "error")} prohibited this category from being saved:"
%ul
- #category.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
= f.text_field :name
%p Sub categories
= f.fields_for :children do |child|
= child.text_field :name
.actions
= f.submit 'Save'
The problem here is that I only end up with one sub category in my form and it doesn't have name set to 'test' so I don't believe that it's actually the child of the category showing here.
What am I missing here?
Can this be done?
Is there an easier way?
Update
If I change my form to the following then it displays three sub categories each with name set to 'test'. This will not save correctly though.
%p Sub categories
- #category.children.each do |sub|
= f.fields_for sub do |child|
= child.label :name
= child.text_field :name
%br
Found my answer and wrote a wiki page about it here:
https://github.com/collectiveidea/awesome_nested_set/wiki/nested-form-for-nested-set