I'm making an "instruction/contact application for internal use".
What i am trying to do
When an instruction is sent from the store manager (user) to the employee (staff)
Enter the name of the employee who will give instructions in the drop-down
Enter and submit the instructions (comment)
The store manager has a list of instructions sent by him
Employees want to be able to see the comments they have received.
I tried to see a list of instructions that came to me.
Use an if statement because it's for you The place where the comment is displayed when the staff and name match (micropost.staff == user.name)
I got an error and couldn't proceed.
] (d31e3e3bf2713761c3affb4d434023e0.png) p> Source code
class CreateMicroposts</pre> <p>migrate/users</p> <pre><code data-language = "rails">class CreateUsers</pre> <p>views/microposts/index</p> <pre><code data-language = "rails">Instructions for yourself <ul> <% @ microposts.each do | micropost |%> <% if micropost.staff == user.name%> <li><% = micropost.comment%></li> <% end%> <% end%> </ul>
def index @microposts = Micropost.all @user = User.find (params [: id]) end
Is the data in the controller not getting well? Kana
I visited the site and found something called the joins method.
where @user = User.find (params [: id])
I changed it to @microposts = Micropost.joins (: user) but it also gives an error
I'm feeling clogged, so I'll ask a question.
Answer # 1
If the employee has a login function, and the logged-in employee can be taken by current_user
def index @microposts = Micropost.where (staff: current_user.name) end
I can't distinguish employees with the same name, but will they cover the operation?
(Tanaka A Tanaka B Tanaka C ... If B retires, is it a permanent missing number?)
- ruby on rails - i can't comment out using htmlerb begin
- ruby - when deleting a post, i want to delete the comment associated with the model together
- ruby "i want to display the price per person"
- i would like to add a comment function to the ruby on rails tutorial undefined method `coments' appears and cannot be solved
- ruby - i want to display the comment posting column with rails so that the comment list can be seen
- ruby - i made a comment model, post model, user model relation with rails, but commentusername is a nil error
- ruby on rails 5 - rails comment function is implemented asynchronously, but deletion does not work
- ruby on rails - comment function deletion
- ruby - data is not stored when implementing the comment function
- ruby - if you try to delete a comment post, you will get an error `destroy' for nil:nilclass please solve it
- ruby on rails - about specifying rails url helper
- ruby on rails 6 - rails public specifying the absolute path of the image below
- ruby on rails 5 - scope by specifying conditions for parent-child relationship
- ruby - i want to be able to see "liked posts" by the person on the rails development user detail page
- ruby - i got a routing error when i sent a comment
- ruby - i get a nomethoderror when i post a comment i want to be able to post comments
- ruby - please tell me the cause of the error when specifying model: of form_with
- ruby - rails comment function display
- ruby on rails - i cannot save a comment on the comment posting page
- ruby - unpermitted parameter: i want to resolve: comment
- i want to convert chinese numerals to alphanumeric characters using gsub with ruby
- [ruby] i'm having trouble with nomethoderror
- ruby - if you try to make the value of the array (json) sent on the vue side a strong parameter, a nomethoderror error will occu
- ruby - i want to display the edit button and delete button on the index page
- ruby - i want to generate a random password (mixed alphanumeric characters)
- ruby - sass :: syntaxerror on rails s
- ruby - i want to display new posts i made on the top page only for myself
- ruby - [rails] i want to deploy a rails application using elastic beanstalk
- ruby - dealing with validation errors when rendering rails apps (definition of instance variables)