当我点击表单上的提交按钮时,它会触发响应,但它没有使用新对象刷新我的页面。帮助
终端响应
Started GET "/activity/individual?utf8=%E2%9C%93&pub_date=02%2F27%2F2016+-+02%2F29%2F2016&influencer_id=22" for 127.0.0.1 at 2016-05-18 11:55:54 -0700
Processing by ActivityController#individual as JS
Parameters: {"utf8"=>"✓", "pub_date"=>"02/27/2016 - 02/29/2016", "influencer_id"=>"22"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Profile Load (0.2ms) SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT 1 [["user_id", 1]]
(0.2ms) SELECT "accounts"."slug" FROM "accounts" INNER JOIN "accounts_users" ON "accounts"."id" = "accounts_users"."account_id" WHERE "accounts_users"."user_id" = $1 [["user_id", 1]]
(0.4ms) SELECT COUNT(*) FROM "influencer_feeds" WHERE "influencer_feeds"."influencer_id" = 22 AND "influencer_feeds"."influencer_id" = 22 AND ("influencer_feeds"."pub_date" BETWEEN '2016-02-27 00:00:00.000000' AND '2016-02-29 00:00:00.000000')
Rendered activity/individual.js.haml (0.1ms)
控制器
def individual
respond_to do |format|
format.html
format.js
end
end
表格
= form_tag("/activity/individual", format: 'js', method: "get", remote: "true", multipart: 'true') do
(parameters)
=submit_tag
JS
- if params[:mode] == "append"
$('#activity_feed_container').append('#{j (render "activity/individual", feed: @feed, influencer: @influencer, twitter_account: @twitter_account, type: @type) }')
- if params[:mode] == "new"
$("#activity_feed").html('#{j (render "activity/individual", feed: @feed, type: @type) }')
$("#activity_feed_container").data("page", 1)
$(".show_more_div").show()
- if (!@feeds || -1 == @feeds || (@feeds && @feeds.count < Settings.activity_feed.page_size))
$(".show_more_div").hide()
:plain
if($('body').hasClass('ie9')){
IE.resizeCols()
}
活动/个人观点(活动/ _individual.html.haml)
.fluid-row
= render "discovery/prospect_rank", prospect: @influencer_prospect
-if (can? :individual, Activity)
- if @feed.blank?
.fluid-row
.panel
%p= "No Activity Content for this Influencer"
- else
.activity-feed-toolbar
= form_tag("/activity/individual", format: 'js', method: "get", remote: "true", multipart: 'true') do
.fluid-row
.small-5.columns
%h3 Activity Feed
-if can? :filter_individual, Activity
.small-7.columns
.fluid-row
.small-6.columns
#date_range.dates
-# %input.activity_data_range{:type=>"text"}
%input#pub_date{name: 'pub_date', :type=>"text", :placeholder => " mm/dd/yyyy - mm/dd/yyyy", value: @pub_date}/
%div.calendar-overlay
.small-6.columns
.activity-feed-filter
-# = select_tag "activity_filter_select", options_for_select({'Last 200 Tweets' => 'last_200', 'Most Recent Relevant' => 'all', 'Relevant Twitter' => 'twitter', 'Relevant RSS' => 'rss'}), class: "filter-select"
= hidden_field_tag :influencer_id, params[:influencer_id].to_i
.small-2.columns.secondary-search-filters
= submit_tag "Apply", {:name => nil, class: 'feed-filter button', id: 'override-default-button-margin-bottom'}
.fluid-row
.small-12.columns.no-padding.feeds-container#activity_feed_container{:data => {:page => 1}}
= render partial: 'influencer_feed/feed', locals: {feed: @feed}
.fluid-row
.small-12.columns.no-padding
- if @page.to_i <= @total_pages
.show_more_div.center
%a.button.radius.center.case-normal.activity_show_more#global_activity_pagination
:javascript
$(document).off( "mouseup", "body");
activityFeedSearchOptions()
DatepickerRange.init()
答案 0 :(得分:0)
@lusketeer是对的。加入当地人有所帮助。但是我还需要更改JS,因为它没有正确地获取params [:mode]。所以我做到了:
- if params[:mode] == "new"
$("#activity_feed").html('#{j (render "activity/individual", locals: { feed: @feed, type: @type}) }')
$("#activity_feed_container").data("page", 1)
- else
$("#activity_feed").html('#{j (render "activity/individual", locals: { feed: @feed, type: @type, pub_date: @pub_date}) }')