Skip to content

Instantly share code, notes, and snippets.

View swaathi's full-sized avatar
💃

Swaathi Kakarla swaathi

💃
View GitHub Profile
var Songs = React.createClass({
render() {
var showSongs = (song) => <Song name={song.name} artist={song.artist} key={song.id}/>;
return <ul>{this.props.songs.map(showSongs)}</ul>;
}
});
@swaathi
swaathi / _songs_container.js.jsx
Created September 16, 2015 17:55
Songs Container
var SongsContainer = React.createClass({
componentWillMount(){
this.fetchSongs();
},
fetchSongs() {
$.ajax({
url: this.props.songsPath,
@swaathi
swaathi / index.html.erb
Created September 16, 2015 12:53
React Component
<p id="notice"><%= notice %></p>
<h1>Listing Songs</h1>
<%= react_component "SongsContainer", { songsPath: songs_path(:json), searchPath: search_path } %>
<%= link_to 'New Song', new_song_path %>
@swaathi
swaathi / songs_controller.rb
Last active September 16, 2015 12:34
Elasticsearch with Searchkick gem
def search
@songs = Song.search(params[:query])
if request.xhr?
render :json => @songs.to_json
else
render :index
end
end
@swaathi
swaathi / files_controller.rb
Last active July 22, 2016 08:06
Preview files outside Public or Assets folder in Rails
# In your controller use the Rails in-built function, send_file to send the file to your browser for preview.
# Specify the filepath of your file in the send_file function.
def preview
send_file "#{Rails.root}/uploads/pictures/#{@file.name}"
end