Ruby on rails 如何使用mailboxer回复帖子用户
我一直在使用mailboxer gem为我的rails应用程序进行用户按摩 由于某些原因,我无法呈现消息表单,并且没有传递我的值,如user.id 这样做的方法是什么?我知道我很接近,但我很喜欢这个 在我的视图/posts/show.html.erb中:Ruby on rails 如何使用mailboxer回复帖子用户,ruby-on-rails,ruby,ruby-on-rails-4,mailboxer,Ruby On Rails,Ruby,Ruby On Rails 4,Mailboxer,我一直在使用mailboxer gem为我的rails应用程序进行用户按摩 由于某些原因,我无法呈现消息表单,并且没有传递我的值,如user.id 这样做的方法是什么?我知道我很接近,但我很喜欢这个 在我的视图/posts/show.html.erb中: <strong>title & author</strong> <h2><%= @post.title %></h2> <p><%= @post.au
<strong>title & author</strong>
<h2><%= @post.title %></h2>
<p><%= @post.author %></p>
</div>
<strong>course</strong><br />
<h1><%= @post.course %></h1>
<strong>school</strong><br />
<h1><%= @post.school %></h1>
<strong>price</strong><br />
<h1><%= @post.price %></h1>
<p>
<strong>Posted by</strong><br />
<%= @post.email %>
</p>
<br />
<h2>Description</h2>
<h1><%= word_wrap(@post.description, :line_width => 8) %></h1>
<br />
DATE POSTED: <%= @post.created_at %><br /><br />
</div>
<%= link_to "reply", new_message_path %>
<!--%= render 'messages/form', conversation: conversation % -->
Reply:
<%= form_for :message, url: [:reply, conversation] do |f| %>
<%= f.text_area :body %>
<%= f.submit "Send Message", class: 'btn btn-primary' %>
<%= submit_tag 'Clear Reply Box', type: :reset, class: 'btn btn-danger' %>
<% end %>
视图/消息/_form.html.erb:
<strong>title & author</strong>
<h2><%= @post.title %></h2>
<p><%= @post.author %></p>
</div>
<strong>course</strong><br />
<h1><%= @post.course %></h1>
<strong>school</strong><br />
<h1><%= @post.school %></h1>
<strong>price</strong><br />
<h1><%= @post.price %></h1>
<p>
<strong>Posted by</strong><br />
<%= @post.email %>
</p>
<br />
<h2>Description</h2>
<h1><%= word_wrap(@post.description, :line_width => 8) %></h1>
<br />
DATE POSTED: <%= @post.created_at %><br /><br />
</div>
<%= link_to "reply", new_message_path %>
<!--%= render 'messages/form', conversation: conversation % -->
Reply:
<%= form_for :message, url: [:reply, conversation] do |f| %>
<%= f.text_area :body %>
<%= f.submit "Send Message", class: 'btn btn-primary' %>
<%= submit_tag 'Clear Reply Box', type: :reset, class: 'btn btn-danger' %>
<% end %>
回复:
基本上,我想在帖子中添加一个回复按钮,让用户向发布帖子的用户发送消息。我正在使用Desive,所有用户都已登录。您应该在路由中的post下定义嵌套的新消息。rb
resources :posts do
resources :messages, only: [:new, :create]
end
那会给你一条路
new_post_message GET/posts/:posts_id/messages/new messages#create
您可以将帖子指定为链接的一部分
<%= link_to 'reply', new_post_message_path(@post) %>
它将参数[:post_id]传递给messages控制器中的create方法,以便您可以检索post,将其设置为实例变量,并在view/messages/new格式中使用它。我没有评论,它是messagesHi,是的,对不起,我有一个高级时刻。修改了答案,希望对大家更有用!