这个教程代码是ERB格式,但我在HAML中这样做。
ERB代码:
if [[ $(ls /some/dir/) ]]; then echo "huzzah"; fi;
我现在在HAML中有什么:
<%= form_tag search_movies_path, method: :get, class: "navbar-form navbar-right", role: "search" do %>
<p>
<%= text_field_tag :search, params[:search], class: "form-control" %>
<%= submit_tag "Search", name: nil, class: "btn btn-default" %>
但它不起作用。有谁知道怎么做?
我的搜索方法如下:
- if user_signed_in?
= link_to current_user.name, edit_user_registration_path
= link_to "Sign Out", destroy_user_session_path, method: :delete
= link_to "Selling", new_post_path, class: "button"
= form_tag posts_path, :method => :get do
= text_field_tag :search, params[:search]
= submit_tag "Search", name: nil, class: "btn btn-default"
- else
= link_to "Sign in", new_user_session_path
= link_to "Sign Up", new_user_registration_path
= link_to "Selling", new_post_path, class: "button"
= form_tag posts_path, :method => :get do
= text_field_tag :search, params[:search]
= submit_tag "Search", name: nil, class: "btn btn-default"
答案 0 :(得分:0)
您已定义了一个名为PostsController
的动作(大概在search
中),但您引用了posts_path
,index
将转到index
行动。您需要将代码放入search_posts_path
或使用search_posts_path
。
这里是您发布的ERB的等效HAML,使用= form_tag search_posts_path, method: :get, class: "navbar-form navbar-right", role: "search" do
%p
= text_field_tag :search, params[:search], class: "form-control"
= submit_tag "Search", name: nil, class: "btn btn-default"
来点击您定义的操作:
SELECT `u`.`id` AS user_id, username,
(SELECT COUNT(message_user.message_read)
FROM message_user
WHERE message_user.message_read = 0
AND sent_id = user_id
AND receive_id = {$userId}) as unread
FROM `user` AS `u`
LEFT JOIN `message_user` AS `mu`
ON
(CASE WHEN `u`.`id` != {$userId}
THEN `u`.`id` = `mu`.`sent_id`
WHEN `mu`.`sent_id` = {$userId} AND `mu`.`receive_id` = {$userId}
THEN `u`.`id` = `mu`.`sent_id`
END)
OR
(CASE WHEN `u`.`id` != {$userId}
THEN `u`.`id` = `mu`.`receive_id`
END)
LEFT JOIN `message` AS `m` ON `m`.`id` = `mu`.`message_id`
WHERE u.id IN
(SELECT contact_id FROM allowed_contact WHERE user_id = {$userId})
GROUP BY u.id
ORDER BY MAX(`m`.`timestamp`) DESC;