I have a major problem with my application. I am new at RoR and got a task from my instructor.
In the task, there's a file like this in view:
views:
account (file)
edit.html.erb
tips (file)
index.html.erb
I need to reach action for account->tips->index.html.erb. I wanted to get all the tips that logged in user added to the application. For that part, I am using this code:
user = User.find(session[:user_id])
@tips = user.tips
When I rendered that page I am getting this output: Processing by Account::TipsController#index as HTML.
But I don't know how to write that index action or where to write.
I have tried to write directly in AccountController as index action, it's not working. And also tried to write in TipsController, it's not working as well.
PS: I have another file called 'tips' and it also has an index action.
PS: I cannot change the file order.
Thanks in advance,
Have a safe day!
You don't need to add tips folder to the account views folder. Keep it separate. Moreover, you need to show the TipsController. If it is separate, then the hierarchy should be as follows. -> app/views/tips/index.html.erb
I have found the answer and would like to share:
In controller, there is automatically created account file which contains tips_controller in it. Inside of the TipsController under Account is like this:
module Account
class TipsController < ApplicationController
def index
@tips = current_user.tips
end
end
end
Somehow I didn't see this controller for hours!
Have a safe and nice day!
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.