This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SongsContainer = React.createClass({ | |
componentWillMount(){ | |
this.fetchSongs(); | |
}, | |
fetchSongs() { | |
$.ajax({ | |
url: this.props.songsPath, | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search | |
@songs = Song.search(params[:query]) | |
if request.xhr? | |
render :json => @songs.to_json | |
else | |
render :index | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder