last day (14 days later) » 

12:43 PM
0
A: Find the Data in Ruby on rails

Nitin Vermain home controller def index end def xyz @report = Ireport.where(reference: params[:report][:reference], weight: params[:report][:weight]).first end and for form field on index page. <%form_for :report, :url => xyz_path do |f| %> <%= f.label_for :reference %> <%= f.input_field :referen...

 
error undefined local variable or method `xyz_path'
 
you have to add route in your routes file. I am updating answer.
 
can update without user, i not use user model
 
yes have updated answer.
 
got error undefined method `label_for' for #<ActionView::Helpers::FormBuilder:0x0000010132d7a8>
 
12:43 PM
try f.label or remove that and create label with pure html.
 
it not show in home#index
 
remove label for now and see other things are working or not
 
i remove label but not display
 
What is not displaying ?
 
home#index not display that form
 
12:54 PM
Where you put your form on home/index.html.erb ?
 
<div class="col-md-4">
<div class='find-report'>

<% form_for :report, :url => xyz_path do |f| %>
<%= f.label :reference %>
<%= f.text_field :reference %>
<%= f.label :weight %>
<%= f.text_field :weight %>
<%= f.submit %>
<% end %>

</div>
</div>
views/home/index
 
Ye I got solution
<%= form_for :report, :url => xyz_path do |f| %>
forgot = on form
is this work for you ?
 
yes then ok, how to display result in xyz
 
you have object @report in xyz method this is a report object you can show whatever you want related to @report in home/xyz.html.erb
 
yes i want display ireport reportnumber, weight
how can i display in xyx.html.erb
 
1:04 PM
on view you can right <%= @report.report_number %> and <%= @report.weight %>
and write render 'xyz' in xyz method
def xyz
@report = Ireport.where(reference: params[:report][:reference], weight: params[:report][:weight]).first
end
def xyz
@report = Ireport.where(reference: params[:report][:reference], weight: params[:report][:weight]).first
render 'xyz'
end
 
got error
No route matches [POST] "/xyz"
but already added get '/xyz', to: 'homes#xyz', as: 'xyz'
 
get '/xyz', to: 'homes#xyz', as: 'xyz' this route is get
try this post '/xyz', to: 'homes#xyz', as: 'xyz' if not works let me know where you get error
 
yes get error
Routing Error
uninitialized constant HomesController
 
yes it is here post '/xyz', to: 'homes#xyz', as: 'xyz' try change post '/xyz', to: 'home#xyz', as: 'xyz'
I think you are quite new in ror
 
it's work
after rails server reload
another it's <%= @report.reference %> and <%= @report.weight %>
undefined method `reference' for nil:NilClass
my schema create_table "ireports", force: true do |t|
t.integer "reportnumber"
t.integer "weight"

t.text "comment"
t.datetime "created_at"
t.datetime "updated_at"
end
t.string "reference"
 
1:18 PM
@reoprt object is nil this time
try print @repert object in xyz method
 
yes
what, i not understand
def xyz
@report = Ireport.where(reference: params[:report][:reference], weight: params[:report][:weight]).first
render 'xyz'
end
this def xyz
 
def xyz
@report = Ireport.where(reference: params[:report][:reference], weight: params[:report][:weight]).first
puts @report
render 'xyz'
end
and see on cosole what @report value is
 
what i put in rails console?
 
this line puts @report will generate log on console
 
2.1.1 :001 > @report
=> nil
2.1.1 :002 >
 
1:29 PM
So there is no record which have parameter you supplied
 
how can i do this error?
 
Can't get you. try find value that is present in your database
 
wow wow it's work
 
that's greate
 
if not find any thing how to redirect root_url
 
1:40 PM
def xyz
@report = Ireport.where(reference: params[:report][:reference], weight: params[:report][:weight]).first

if @report.blank?
redirect_to root_url
else
render 'xyz'
end
end
Can you upvote if it's work for you :)
thanks :)
 
2:02 PM
thanks :) thanks :)
 

last day (14 days later) »