Is there a way to route to multiple files in my views in Ruby on Rails - html

I am making a website dedicated to flash and unity games to learn Ruby on Rails hands on and I wanted to know if there was a way to route to all the documents in a folder without entering them in the routes file one by one. I am not sure if I am just being blind, but I have been looking everywhere for an answer.
For example i have to enter:
Get 'game1', to: "games#game1"
In the routes file for an individual game, but I want to be able to add a entire library without having to enter them in one by one.

correct me if i'm wrong, but you have several files (games) into the games view folder and you want to route through a single action?
so, basically, in your routes.rb would have:
get "games/:game_number" => "games#show"
and then, on your games_controller.rb
def show
# ...
render "games/#{params[:game_number]}"
end
so, in this case, if you hit /games/first, it would render the view games/first.html.erb
this is not a good practice since the are several pitfalls through out, but, having that in mind, this should work if i got the right scenario :)

This is what variable segments are for. You should be using something like
get "games/:id" => "games#show"
and looking up the game by params[:id].

Related

Scan an area of a web page's source code for changes while reporting it?

this is one heck of a confusing question to ask so here it goes. Firstly, I'm not asking you to write me any code I just need help going in the right direction for what I'm trying to achieve here. Basically the task is this, I want to scan a select area of a web page's source code for changes and if something does change, I want to report it somewhere (like a console or something). However, I do not want just a notification of change, I also want what the change is/was. I've been looking into things like jsoup but I am still struggling to even find out what this is called.
Any pointers would be insanely appreciated. Thanks, Optimistic.
Here are some steps assuming this is from a node.js project:
Get the URL for the specific script file you're looking for a change in.
Using the request() module, fetch that URL.
Break the data up into lines (probably using .split()).
Find the specific line you are looking for either by counting line numbers of by searching for some representative text in that line.
Using some sort of search in that line (perhaps a regex), find the current value of the exact item in that line you are looking for.
Save the current value.
Then, at some future time, repeat this whole process and compare what you find to the previous value.
If this is being done from a browser instead of node.js, then use an Ajax call to retrieve the file. If the file is on another domain from your web page and that domain does not permit cross-origin requests, then you cannot solve this problem in an automated fashion from a browser in your own web page.
Here is how I would do it with Jsoup:
Document doc = Jsoup.connect(url).get();
String scriptCssQuery = "script"; // Tune this CSS query to find THE script you need.
Element script = doc.select(scriptCssQuery).first();
if (script != null) {
String scriptLines = script.html();
// Store the changing line somewhere and compare it to its previous value...
}

yii2: where do my project's own html, css, js, and php-include files go?

Choices:
create an asset bundle (nicely explained by Ivo Renkema at How do I manage assets in Yii2?). this is what I need if I want to package my code for other use. alas, should I also do this for my own php include library functions? Or should I still stick them into the same php location as my other php files? In any case, if I want to go this route, presumably I would then customize the AppAsset class, included in the template, as explained in http://www.yiiframework.com/doc-2.0/guide-structure-assets.html .
stick my files directly into $basePath/web, where $basePath is typically something like /var/www/myapp/ (i.e., as $basePath/html/mine.html [and refer to it simply as href='/html/mine.html'], $basePath/css/mine.css , $basePath/js/mine.js, and $basePath/php/mine.php [and refer to it as $basePath= \Yii::getAlias('#webroot'); require_once('$basepath/php/mine.php') ])?
stick my local files where my php view code sits. the advantage is that the files are close to where I will use them. the disadvantage is that I may litter the view directories not only with php files, but also with my non-asset assets, even though they will be used only by these (my) php files.
it's a beginner's question for the google cache reference. it's about best practice when getting started. I can guess the answer, but we wouldn't want a novice to disseminate bad info.
If you need your CSS and JS files only in one view or one Controller you have 2 choices:
1- Create a asset bundle Here other guide if you need it.
2- Use registerJsFile() from View Class
You can acces from controller using:
Yii::$app->view->registerJsFile('js.path');
(Same with CSS files but using registerCssFile())
With the PHPfiles I always try to convert the code to yii's MVC. If you have a entire library try to add it as a component. Here a usefull guide

Multiple Shiny apps using the ui to populate the second app

I currently have a app that manages projects. The user sees a list of projects and can select one. They can should (it would be nice) be able to click a run button and have another app open. The parameters stored in the project they selected are populated into the second application. The issue I am having is firing the second application. runApp generates the following.
ui code line:
actionButton("RunProj", "Run"),
Warning in run(timeoutMs) :
Unhandled error in observer: Key / already in use
observeEvent(input$RunProj)
I would like to trigger the second app and pass in the location of the project directory I have looked at parseQueryString and still trying to figure out a way to include that. Maybe via a redirect?
Any suggests would be much appreciated.
Regards,
Rich
I'm not 100% sure if I understand your intention correctly but here is a few things I think you may want to think about.
In one project, if you want to run a few kinds of analyses, you may want to try navbarPage
If there are many different types of analyses, you may want to try shinydashboard
If you know the link to each app and you really want to add those "run" buttons, you can add a button manually in ui.R. I think you can write some codes in server.r to generate the link based on your database.
tags$a(href="the link to your apps", class= "btn btn-default", "Run App")

Fetching previous revisions of multiple files via Google Drive API?

While trying to import some Android projects into Eclipse, I have noticed that every file in the project is 0 bytes after they are imported. These projects are stored on Drive, so there is some chance of reverting them back to the previous version.
Reverting files to previous versions is easy to do when you've got a few files - you simply do it through a browser. However, I have hundreds of files and I need to fetch one revision back for each. I have been able to download a number of files by hand thus far, but there has to be a better way.
I have asked Google support and actually got a response back, but it's clear that there is no built-in functionality to do this. So I have started looking at the Drive API but I can see that there might be a bit of a learning curve.
Wondering if anyone has run into this before? Ideally I would like to identify one folder and for each file underneath, fetch the last version of the file. If anyone has a good approach for this, I would love to hear it.
thanks!
The pseudeo code to do what you want is
# get the id of the folder https://developers.google.com/drive/v2/reference/files/list
fid=file.list(q=title = 'foo')[0]
# get the children of that folder https://developers.google.com/drive/v2/reference/children/list
children = file.children(fid).maxresults=999
# for each child,
for id in children.id
# get the revisions https://developers.google.com/drive/v2/reference/revisions/get
revisions = file.revisions(id)
# iterate, or take item[1] whatever works best for you, and use its downloadUrl to fetch the file
With each call that you make, you'll need to provide an access token. For something like this, you can generate an access token using the oauth playground https://developers.google.com/oauthplayground/
You'll also need to register a project at the cloud/api console https://code.google.com/apis/console/
So ye, it's a disproportionate amount of learning to do something fairly simple. It's a few minutes work for somebody familiar with drive, and I would guess 3 days for somebody who isn't. You might want to throw it up on freelancer.com.

Create an aMember plugin to integrate with Interspire

I need to integrate aMember with Interspire. I need aMember to completely sync with Interspire. When users register for aMember, they are also placed in the Interspire database, and are placed in the right group so that we may restrict access.
I have searched for a plugin to do this, and haven't found anything. I have also tried to make the plugin myself, but I have found no basic samples of such a plugin. I looked on the Wiki but the info and examples there are not much help. I have also tried to look at other plugins for other systems, but sense those other systems are different from Interspire, the way they are handled is not exactly how you would handle integrating with Interspire, so I was wondering if there is something we can do to get this plugin made, Or some more examples to look at that better explain how to make the plugin myself.
I know this is an old question, however I have a solution I have used and it works. Just answering this in the event you never found the solution, or someone else stumbles upon this and needs an answer.
You don't need to create a plugin for aMember. Using cURL in PHP you can make 1 action perform 2 things at the same time.
You would need to modify the registration step. It has been a while since I looked in the amember code to tell you which php file to edit, ect and its different probably with different amember versions..
On your registration form you should have HTML code for the form, it's action URL should point you to the correct file. It would start something like:
<form action="registration.php" method="post" class="something">
rest of the code here...
So in that example, I would look at registration.php and it should then take the data the user entered and handle it. it probably checks if the users exists in your amember users, if not then it adds them. At that point, you know everything is good and if your amember is setup to then send the user to paypal, it may have code for starting the payment integration. Between those steps (after it added the user to your db and before it sends them off to go pay) add your own code. You could just add the php code right there to use curl and add them to interspire. My way, I would create a function and just add 1 line of code to this file to call that function.
AddToIEM(firstname,lastname,ip,email)
Then there is probably a functions.php file for amember. In that file, i would create a function to add take their info passed above and add them into your IEM.
Additionally, you could take the plugin amember has for Aweber integration and modify it to use Interspire.
This is just an idea outline, and not real working code. You will need to lookup curl and figure out how to use it to add them into your interspire.
You can do this pretty easily with the amember hook system. I actually will probably be doing this sometime soon. If I do, I'll try to post a snippet. In the meantime, just take a look at the signup hooks in amember.