1

I am integrating 2 rails projects using button to link the first project to the second. Now I have this code

<%= form_tag fast_url_for(' ') do %>
  <%= button_to AppConfig.app_clockout %>
<% end %>

and my current directory is

/var/www/html/wizTime/wizProject/Source/project_1

but I don't know how can this redirect to the home page of another project. The directory of my second project that I want to integrate is

/var/www/html/project_2

Please give me ideas. Thank you!

skyranch
  • 55
  • 5
  • why do you need to link a *form* to another project? Do you just want a button/link to the other project? If so - no problem, but not sure that depending on directory-structure is a good way of doing that... when you eventually deploy these projects - will they have their own domains? or subdomains? Generally speaking, Rails projects are run independently of one another. You don't just mangle two of them together like this. – Taryn East Feb 16 '17 at 04:30
  • Coz that's how I know to link to another page on a button click. Yes, I just want a button linking to another project and will display its home page. Will that be possible? – skyranch Feb 16 '17 at 05:22
  • Yes, they will have their own domains when deployed. – skyranch Feb 16 '17 at 05:30

2 Answers2

3

If you only want a link_to and your projects will have domains later, you can just create a link like this in rails: <%= link_to 'sec project', "http://www.rubyonrails.org/" %> which will create an ordinary html link: <a href=""http://www.rubyonrails.org/" ...> The form usually should not link to another project?! If after submitting the form you want to redirect the view to another project, than you can use the controller action and redirect after submit.

KcUS_unico
  • 513
  • 3
  • 9
1

As the other commenter said - you can just create a link to the other domain. You should not ever rely on your directory-structure - because when you deploy, that directory structure will very likely be subtly different.

So use the domains instead.

You can even put the domains into environment variables so that you can use different domains (eg localhost:3000 vs localhost:3001) on your development machine. you'd use them like this:

<%= link_to 'My App', ENV['MY_APP_DOMAIN'] %>
<%= link_to 'My Other App', ENV['MY_OTHER_APP_DOMAIN'] %>

Then google for how to set environment variables on your local machine to set the values.

If you want them to be buttons... then you don't need to use a form. button_to creates its own form and is used exactly the same way as a link_to eg:

<%= button_to 'My App', ENV['MY_APP_DOMAIN'] %>
<%= button_to 'My Other App', ENV['MY_OTHER_APP_DOMAIN'] %>

However... you really don't need to use a button-to if you are just doing a GET for a URL like this...

(you use buttons when you need to POST data eg POSTing form data to a create action)

You can just pass in a CSS-class and style the link-to to look as though it were a button.

eg using Bootstrap classes:

<%= link_to 'My App', ENV['MY_APP_DOMAIN'], class: 'btn btn-success' %>
<%= link_to 'My Other App', ENV['MY_OTHER_APP_DOMAIN'], class: 'btn btn-danger' %>

OR similar.

Taryn East
  • 27,486
  • 9
  • 86
  • 108
  • Thank you! I just had to run localhost:3001 in another terminal as well and everything's working fine. Now I'm having a problem on how to get the authenticated user from project 1 to be able to authenticate it also to the other project. Both projects have login features but I want the user to be able to login to the second project when already logged in on the first project. Any ideas would be of great help. Thank you again! – skyranch Feb 17 '17 at 01:13
  • Firstly - I'd google "single sign on rails" and see how much you can find out about it... it's not as easy as you'd think. If you get stuck... then ask a new question on Stack Overflow and we'll help you :) – Taryn East Feb 17 '17 at 01:20
  • Oh, idk about single sign on in rails. Thanks! – skyranch Feb 17 '17 at 01:31
  • Yeah, it's probably where you want to go with being able to authenticate across multiple apps... unless you want to use oauth (eg "sign in with your facebook/google account"). There are multiple ways of doing it, but googling that phrase will give you a good idea of what's out there. – Taryn East Feb 17 '17 at 01:35