ruby on rails - How to replace object with coffee script? -


I am creating a user notification system and there is a problem, I do not know how to refresh my @activities on my header layout I'm:

application_controller.rb

  before_filter: activity def track_activity (user, trackable, action = param [: action], author = current_user) activity . Create! Users: User, Trackable: Trackable, Action: Action, Author: Author PrivatePub.publish_to ("/ Message / New", Good: Activity) End DIF Activity if signed_in? @activities = current_user.activities.includes (: author,: trackable) .order (created_at :: desc) end-of-end   

layout / _header.html.erb

  & lt; Div class = "user-notification" & gt; & Lt; One class = "FA-FA-life-ring FA-LG" href = "javascript: zero (0);" tabindex = "1" & gt; & Lt; / A & gt; & Lt; div class = "activity activity_open" id = "activity" & gt; & Lt;% @ activities.each do | Activity | & Gt%; & Lt;% = link_to activity.user.name, activity.user% & gt; & Lt;% = render "activities / # {activity.trackable_type.underscore} / # {activity.action}", activity: activity% & gt; & Lt;% end% & gt; & lt;% = subscribe_to "/ message / new"%> & Lt; / Div & gt; & Lt; / Div & gt;   

javascripts / messages.js.coffee

  Privatepubs subscriptions "/ messages / new", (data, channel) - & gt; Warning $ ("#Activity") Attachments ("& lt;% = data.cool = @ activities%>");   

But the alert shows [object object]

How can I update @activities? help please!

You can not access the example variable in the coffeespace script. If you have to do something partially updated, you can put the eddie code in the view directory corresponding to the action in the file and it can give the same name as the action.

So if the name of the controller is Fu and the action is named bar, you need a file called 'bar.jes' inside 'Controllers / Foo /' in which it has append code. If you need, you can call the coffee script function from that file, but you can not access the frequency variable directly from the coffeizet file.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -