Ruby on Rails Monday, July 21, 2014

I am using Ruby 1.9.3 and Rails 3.2.16.

What i want to do is When i select date in **search** text field, i
would get date corresponding to that date.

> Code in view:

<%= form_tag quantities_path, :method => 'get' do %>
<p>
<%= text_field_tag :search, params[:search], :class => "datepicker"
%>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>

> Code in model:

def self.search(search)
if search
find(:all, :conditions => ['expense_on LIKE ?', "%#{search}%"])
else
find(:all)
end
end

> schema.rb contain:

ActiveRecord::Schema.define(:version => 20140720063348) do

create_table "quantities", :force => true do |t|
t.string "title"
t.decimal "price", :precision => 8, :scale => 2
t.datetime "created_at", :null =>
false
t.datetime "updated_at", :null =>
false
t.string "day"
t.string "month"
t.string "year"
t.date "expense_on"
end
end

> code in controller:

def index
@quantities = Quantity.search(params[:search])
end

By using above code, when i select date in search column, i can not able
get data. How could i get it?

Kind regards.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9b6f8fdb1f39f8dcd819baf4bff4e129%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment