I am new to ruby on rails and working on a project with ruby on rails 4th version. right now i was changing the view of the order in active admin but i am getting errors.
ActiveAdmin.register Order do
permit_params :id, :order_completed, :approved
# changing the visual of view action, so admin user can able to see complete order details
show do |order|
attributes_table do
row :id # Order ID
row 'Name' params[:user].first_name # its not working, not showing the user first_name assiated with order id
# It should be user name. although user first_name is in users table and User model is availble.
row 'Adress' params[:user].address # its not working, not showing the user address assiated with order id
# It should be user address. although user first_name is in users table and User model is availble.
end
end
controller do
def show
order_id = Order.find(params[:id]).user_id
params[:user] = User.find(order_id)
show!
end
end
end
My goal is to show order associated user's details like address, name etc.
Order table consists of
- id
- user_id
- order_completed (boolean)
- approved
- order_status (string) [in process, done]
User table consists of
- id
- first_name
- last_name
- address
- membership_id
I will assuming that you have established the relationship between the class 'Order' and the class 'User' in their respective models. (belongs_to and has_many methods. If you need more help on this let me know.) Then you have to declare that relationship also in Activeadmin when you register the classes, so try this:
app/admin/order.rb:
ActiveAdmin.register Order do
permit_params :id, :order_completed, :approved
belongs_to :user # Declaring that order belongs to user here
# changing the visual of view action, so admin user can able to see complete order details
show do |order|
attributes_table do
row :id # Order ID
row 'Name' do
@order.user.first_name
end
row 'Address' do
@order.user.address
end
end
end
controller do
def show
@order = Order.find(params[:id])
show!
end
end
end`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.